nir: Add ability for shaders to use window space coordinates.
authorTimur Kristóf <timur.kristof@gmail.com>
Tue, 5 Feb 2019 17:08:24 +0000 (18:08 +0100)
committerEric Anholt <eric@anholt.net>
Tue, 5 Mar 2019 19:13:27 +0000 (19:13 +0000)
This patch adds a shader_info field that tells the driver to use window
space coordinates for a given vertex shader. It also enables this feature
in radeonsi (the only NIR-capable driver that supported it in TGSI),
and makes tgsi_to_nir aware of it.

Signed-Off-By: Timur Kristóf <timur.kristof@gmail.com>
Tested-by: Andre Heider <a.heider@gmail.com>
Tested-by: Rob Clark <robdclark@gmail.com>
Reviewed-by: Timothy Arceri <tarceri@itsqueeze.com>
Reviewed-by: Eric Anholt <eric@anholt.net>
src/compiler/shader_info.h
src/gallium/auxiliary/nir/tgsi_to_nir.c
src/gallium/drivers/radeonsi/si_shader_nir.c

index 8fbdfab1a8e19325d1294175284da359d896b9d6..5b229130a1199f0993fe0420e2d111d294d420ab 100644 (file)
@@ -149,6 +149,9 @@ typedef struct shader_info {
       struct {
          /* Which inputs are doubles */
          uint64_t double_inputs;
+
+         /* True if the shader writes position in window space coordinates pre-transform */
+         bool window_space_position;
       } vs;
 
       struct {
index 4f30714a746d51b165a72aa7cf5ae17abd1b2026..cee98444290b2ce52a6ba04b9d84858197a3a1ef 100644 (file)
@@ -1805,6 +1805,8 @@ tgsi_to_nir(const void *tgsi_tokens,
    s->num_uniforms = scan.const_file_max[0] + 1;
    s->num_outputs = scan.file_max[TGSI_FILE_OUTPUT] + 1;
 
+   s->info.vs.window_space_position = scan.properties[TGSI_PROPERTY_VS_WINDOW_SPACE_POSITION];
+
    c->inputs = rzalloc_array(c, struct nir_variable *, s->num_inputs);
    c->outputs = rzalloc_array(c, struct nir_variable *, s->num_outputs);
 
index 812c2172366d7902a7bdbb8d41764e9c74c5fcf6..5e29c8f4ccd7d6948bd23a1379b67f595600f41d 100644 (file)
@@ -343,6 +343,9 @@ void si_nir_scan_shader(const struct nir_shader *nir,
        info->properties[TGSI_PROPERTY_NEXT_SHADER] =
                pipe_shader_type_from_mesa(nir->info.next_stage);
 
+       info->properties[TGSI_PROPERTY_VS_WINDOW_SPACE_POSITION] =
+               nir->info.vs.window_space_position;
+
        if (nir->info.stage == MESA_SHADER_TESS_CTRL) {
                info->properties[TGSI_PROPERTY_TCS_VERTICES_OUT] =
                        nir->info.tess.tcs_vertices_out;