nir/spirv: pull out logic for getting builtin locations
[mesa.git] / src / glsl / glsl_parser_extras.h
index 6459cac64c999ee3c8a23bca6a41f9c19de96b65..9a0c24e67877fbd3dc7557bed920354e2e74da7f 100644 (file)
@@ -40,9 +40,14 @@ struct glsl_switch_state {
    /** Temporary variables needed for switch statement. */
    ir_variable *test_var;
    ir_variable *is_fallthru_var;
-   ir_variable *is_break_var;
    class ast_switch_statement *switch_nesting_ast;
 
+   /** Used to detect if 'continue' was called inside a switch. */
+   ir_variable *continue_inside;
+
+   /** Used to set condition if 'default' label should be chosen. */
+   ir_variable *run_default;
+
    /** Table of constant values already used in case labels */
    struct hash_table *labels_ht;
    class ast_case_label *previous_default;
@@ -100,8 +105,10 @@ struct _mesa_glsl_parse_state {
    {
       unsigned required_version = this->es_shader ?
          required_glsl_es_version : required_glsl_version;
+      unsigned this_version = this->forced_language_version
+         ? this->forced_language_version : this->language_version;
       return required_version != 0
-         && this->language_version >= required_version;
+         && this_version >= required_version;
    }
 
    bool check_version(unsigned required_glsl_version,
@@ -119,6 +126,19 @@ struct _mesa_glsl_parse_state {
       return check_version(130, 300, locp, "bit-wise operations are forbidden");
    }
 
+   bool check_explicit_attrib_stream_allowed(YYLTYPE *locp)
+   {
+      if (!this->has_explicit_attrib_stream()) {
+         const char *const requirement = "GL_ARB_gpu_shader5 extension or GLSL 400";
+
+         _mesa_glsl_error(locp, this, "explicit stream requires %s",
+                          requirement);
+         return false;
+      }
+
+      return true;
+   }
+
    bool check_explicit_attrib_location_allowed(YYLTYPE *locp,
                                                const ir_variable *var)
    {
@@ -140,7 +160,7 @@ struct _mesa_glsl_parse_state {
    {
       if (!this->has_separate_shader_objects()) {
          const char *const requirement = this->es_shader
-            ? "GL_EXT_separate_shader_objects extension"
+            ? "GL_EXT_separate_shader_objects extension or GLSL ES 310"
             : "GL_ARB_separate_shader_objects extension or GLSL 420";
 
          _mesa_glsl_error(locp, this, "%s explicit location requires %s",
@@ -151,11 +171,45 @@ struct _mesa_glsl_parse_state {
       return true;
    }
 
+   bool check_explicit_uniform_location_allowed(YYLTYPE *locp,
+                                                const ir_variable *)
+   {
+      if (!this->has_explicit_attrib_location() ||
+          !this->has_explicit_uniform_location()) {
+         const char *const requirement = this->es_shader
+            ? "GLSL ES 310"
+            : "GL_ARB_explicit_uniform_location and either "
+              "GL_ARB_explicit_attrib_location or GLSL 330.";
+
+         _mesa_glsl_error(locp, this,
+                          "uniform explicit location requires %s",
+                          requirement);
+         return false;
+      }
+
+      return true;
+   }
+
+   bool has_atomic_counters() const
+   {
+      return ARB_shader_atomic_counters_enable || is_version(420, 310);
+   }
+
+   bool has_explicit_attrib_stream() const
+   {
+      return ARB_gpu_shader5_enable || is_version(400, 0);
+   }
+
    bool has_explicit_attrib_location() const
    {
       return ARB_explicit_attrib_location_enable || is_version(330, 300);
    }
 
+   bool has_explicit_uniform_location() const
+   {
+      return ARB_explicit_uniform_location_enable || is_version(430, 310);
+   }
+
    bool has_uniform_buffer_objects() const
    {
       return ARB_uniform_buffer_object_enable || is_version(140, 300);
@@ -163,10 +217,15 @@ struct _mesa_glsl_parse_state {
 
    bool has_separate_shader_objects() const
    {
-      return ARB_separate_shader_objects_enable || is_version(410, 0)
+      return ARB_separate_shader_objects_enable || is_version(410, 310)
          || EXT_separate_shader_objects_enable;
    }
 
+   bool has_double() const
+   {
+      return ARB_gpu_shader_fp64_enable || is_version(400, 0);
+   }
+
    void process_version_directive(YYLTYPE *locp, int version,
                                   const char *ident);
 
@@ -179,10 +238,11 @@ struct _mesa_glsl_parse_state {
    struct {
       unsigned ver;
       bool es;
-   } supported_versions[12];
+   } supported_versions[15];
 
    bool es_shader;
    unsigned language_version;
+   unsigned forced_language_version;
    gl_shader_stage stage;
 
    /**
@@ -293,6 +353,16 @@ struct _mesa_glsl_parse_state {
       unsigned MaxCombinedAtomicCounters;
       unsigned MaxAtomicBufferBindings;
 
+      /* These are also atomic counter related, but they weren't added to
+       * until atomic counters were added to core in GLSL 4.20 and GLSL ES
+       * 3.10.
+       */
+      unsigned MaxVertexAtomicCounterBuffers;
+      unsigned MaxGeometryAtomicCounterBuffers;
+      unsigned MaxFragmentAtomicCounterBuffers;
+      unsigned MaxCombinedAtomicCounterBuffers;
+      unsigned MaxAtomicCounterBufferSize;
+
       /* ARB_compute_shader */
       unsigned MaxComputeWorkGroupCount[3];
       unsigned MaxComputeWorkGroupSize[3];
@@ -305,6 +375,9 @@ struct _mesa_glsl_parse_state {
       unsigned MaxGeometryImageUniforms;
       unsigned MaxFragmentImageUniforms;
       unsigned MaxCombinedImageUniforms;
+
+      /* ARB_viewport_array */
+      unsigned MaxViewports;
    } Const;
 
    /**
@@ -357,6 +430,8 @@ struct _mesa_glsl_parse_state {
    bool ARB_compute_shader_warn;
    bool ARB_conservative_depth_enable;
    bool ARB_conservative_depth_warn;
+   bool ARB_derivative_control_enable;
+   bool ARB_derivative_control_warn;
    bool ARB_draw_buffers_enable;
    bool ARB_draw_buffers_warn;
    bool ARB_draw_instanced_enable;
@@ -367,8 +442,12 @@ struct _mesa_glsl_parse_state {
    bool ARB_explicit_uniform_location_warn;
    bool ARB_fragment_coord_conventions_enable;
    bool ARB_fragment_coord_conventions_warn;
+   bool ARB_fragment_layer_viewport_enable;
+   bool ARB_fragment_layer_viewport_warn;
    bool ARB_gpu_shader5_enable;
    bool ARB_gpu_shader5_warn;
+   bool ARB_gpu_shader_fp64_enable;
+   bool ARB_gpu_shader_fp64_warn;
    bool ARB_sample_shading_enable;
    bool ARB_sample_shading_warn;
    bool ARB_separate_shader_objects_enable;
@@ -379,6 +458,8 @@ struct _mesa_glsl_parse_state {
    bool ARB_shader_bit_encoding_warn;
    bool ARB_shader_image_load_store_enable;
    bool ARB_shader_image_load_store_warn;
+   bool ARB_shader_precision_enable;
+   bool ARB_shader_precision_warn;
    bool ARB_shader_stencil_export_enable;
    bool ARB_shader_stencil_export_warn;
    bool ARB_shader_texture_lod_enable;
@@ -401,6 +482,8 @@ struct _mesa_glsl_parse_state {
    bool ARB_texture_rectangle_warn;
    bool ARB_uniform_buffer_object_enable;
    bool ARB_uniform_buffer_object_warn;
+   bool ARB_vertex_attrib_64bit_enable;
+   bool ARB_vertex_attrib_64bit_warn;
    bool ARB_viewport_array_enable;
    bool ARB_viewport_array_warn;
 
@@ -426,6 +509,10 @@ struct _mesa_glsl_parse_state {
    bool AMD_shader_trinary_minmax_warn;
    bool AMD_vertex_shader_layer_enable;
    bool AMD_vertex_shader_layer_warn;
+   bool AMD_vertex_shader_viewport_index_enable;
+   bool AMD_vertex_shader_viewport_index_warn;
+   bool EXT_draw_buffers_enable;
+   bool EXT_draw_buffers_warn;
    bool EXT_separate_shader_objects_enable;
    bool EXT_separate_shader_objects_warn;
    bool EXT_shader_integer_mix_enable;
@@ -449,10 +536,12 @@ struct _mesa_glsl_parse_state {
     */
    unsigned gs_input_size;
 
-   bool early_fragment_tests;
+   bool fs_early_fragment_tests;
 
    /** Atomic counter offsets by binding */
    unsigned atomic_counter_offsets[MAX_COMBINED_ATOMIC_BUFFERS];
+
+   bool allow_extension_directive_midshader;
 };
 
 # define YYLLOC_DEFAULT(Current, Rhs, N)                       \
@@ -523,6 +612,9 @@ extern "C" {
 extern const char *
 _mesa_shader_stage_to_string(unsigned stage);
 
+extern const char *
+_mesa_shader_stage_to_abbrev(unsigned stage);
+
 extern int glcpp_preprocess(void *ctx, const char **shader, char **info_log,
                       const struct gl_extensions *extensions, struct gl_context *gl_ctx);