replace _mesa_logbase2 with util_logbase2
[mesa.git] / src / mesa / state_tracker / st_program.h
index 3ec455d27441124969d56a7eb34276bc18fbd8ca..286fabc01172f772d9b80a1526d9ac50fe6152d3 100644 (file)
@@ -71,9 +71,15 @@ st_get_external_sampler_key(struct st_context *st, struct gl_program *prog)
       unsigned unit = u_bit_scan(&mask);
       struct st_texture_object *stObj =
             st_get_texture_object(st->ctx, prog, unit);
+      enum pipe_format format = st_get_view_format(stObj);
 
-      switch (st_get_view_format(stObj)) {
+      /* if resource format matches then YUV wasn't lowered */
+      if (format == stObj->pt->format)
+         continue;
+
+      switch (format) {
       case PIPE_FORMAT_NV12:
+      case PIPE_FORMAT_P010:
       case PIPE_FORMAT_P016:
          key.lower_nv12 |= (1 << unit);
          break;
@@ -94,7 +100,7 @@ st_get_external_sampler_key(struct st_context *st, struct gl_program *prog)
          break;
       default:
          printf("mesa: st_get_external_sampler_key: unhandled pipe format %u\n",
-               st_get_view_format(stObj));
+                format);
          break;
       }
    }
@@ -139,27 +145,36 @@ struct st_fp_variant_key
    struct st_external_sampler_key external;
 };
 
+/**
+ * Base class for shader variants.
+ */
+struct st_variant
+{
+   /** next in linked list */
+   struct st_variant *next;
+
+   /** st_context from the shader key */
+   struct st_context *st;
+
+   void *driver_shader;
+};
 
 /**
  * Variant of a fragment program.
  */
 struct st_fp_variant
 {
+   struct st_variant base;
+
    /** Parameters which generated this version of fragment program */
    struct st_fp_variant_key key;
 
-   /** Driver's compiled shader */
-   void *driver_shader;
-
    /** For glBitmap variants */
    uint bitmap_sampler;
 
    /** For glDrawPixels variants */
    unsigned drawpix_sampler;
    unsigned pixelmap_sampler;
-
-   /** next in linked list */
-   struct st_fp_variant *next;
 };
 
 
@@ -181,61 +196,35 @@ struct st_common_variant_key
 
    /* for user-defined clip-planes */
    uint8_t lower_ucp;
-};
 
-
-/**
- * This represents a vertex program, especially translated to match
- * the inputs of a particular fragment shader.
- */
-struct st_vp_variant
-{
-   /* Parameters which generated this translated version of a vertex
-    * shader:
+   /* Whether st_variant::driver_shader is for the draw module,
+    * not for the driver.
     */
-   struct st_common_variant_key key;
-
-   /**
-    * The shader variant saved for the draw module to later emulate
-    * selection/feedback/rasterpos.
-    */
-   const struct tgsi_token *tokens;
-
-   /** Driver's compiled shader */
-   void *driver_shader;
-
-   /** For using our private draw module (glRasterPos) */
-   struct draw_vertex_shader *draw_shader;
-
-   /** Next in linked list */
-   struct st_vp_variant *next;  
-
-   /** similar to that in st_vertex_program, but with edgeflags info too */
-   GLuint num_inputs;
-
-   /** Bitfield of VERT_BIT_* bits of mesa vertex processing inputs */
-   GLbitfield vert_attrib_mask;
+   bool is_draw_shader;
 };
 
 
 /**
- * Geometry program variant.
+ * Common shader variant.
  */
 struct st_common_variant
 {
+   struct st_variant base;
+
    /* Parameters which generated this variant. */
    struct st_common_variant_key key;
 
-   void *driver_shader;
-
-   struct st_common_variant *next;
+   /* Bitfield of VERT_BIT_* bits matching vertex shader inputs,
+    * but not include the high part of doubles.
+    */
+   GLbitfield vert_attrib_mask;
 };
 
 
 /**
  * Derived from Mesa gl_program:
  */
-struct st_common_program
+struct st_program
 {
    struct gl_program Base;
    struct pipe_shader_state state;
@@ -243,14 +232,19 @@ struct st_common_program
    struct ati_fragment_shader *ati_fs;
    uint64_t affected_states; /**< ST_NEW_* flags to mark dirty when binding */
 
-  /* used when bypassing glsl_to_tgsi: */
+   void *serialized_nir;
+   unsigned serialized_nir_size;
+
+   /* used when bypassing glsl_to_tgsi: */
    struct gl_shader_program *shader_program;
 
-   union {
-      struct st_common_variant *variants;
-      struct st_vp_variant *vp_variants;
-      struct st_fp_variant *fp_variants;
-   };
+   struct st_variant *variants;
+};
+
+
+struct st_vertex_program
+{
+   struct st_program Base;
 
    /** maps a TGSI input index back to a Mesa VERT_ATTRIB_x */
    ubyte index_to_input[PIPE_MAX_ATTRIBS];
@@ -263,22 +257,34 @@ struct st_common_program
 };
 
 
-static inline struct st_common_program *
-st_common_program( struct gl_program *cp )
+static inline struct st_program *
+st_program( struct gl_program *cp )
 {
-   return (struct st_common_program *)cp;
+   return (struct st_program *)cp;
 }
 
 static inline void
 st_reference_prog(struct st_context *st,
-                  struct st_common_program **ptr,
-                  struct st_common_program *prog)
+                  struct st_program **ptr,
+                  struct st_program *prog)
 {
    _mesa_reference_program(st->ctx,
                            (struct gl_program **) ptr,
                            (struct gl_program *) prog);
 }
 
+static inline struct st_common_variant *
+st_common_variant(struct st_variant *v)
+{
+   return (struct st_common_variant*)v;
+}
+
+static inline struct st_fp_variant *
+st_fp_variant(struct st_variant *v)
+{
+   return (struct st_fp_variant*)v;
+}
+
 /**
  * This defines mapping from Mesa VARYING_SLOTs to TGSI GENERIC slots.
  */
@@ -292,32 +298,27 @@ st_get_generic_varying_index(struct st_context *st, GLuint attr)
 extern void
 st_set_prog_affected_state_flags(struct gl_program *prog);
 
-extern struct st_vp_variant *
+extern struct st_common_variant *
 st_get_vp_variant(struct st_context *st,
-                  struct st_common_program *stvp,
+                  struct st_program *stvp,
                   const struct st_common_variant_key *key);
 
 
 extern struct st_fp_variant *
 st_get_fp_variant(struct st_context *st,
-                  struct st_common_program *stfp,
+                  struct st_program *stfp,
                   const struct st_fp_variant_key *key);
 
-extern struct st_common_variant *
+extern struct st_variant *
 st_get_common_variant(struct st_context *st,
-                      struct st_common_program *p,
+                      struct st_program *p,
                       const struct st_common_variant_key *key);
 
 extern void
-st_release_vp_variants( struct st_context *st,
-                        struct st_common_program *stvp );
-
-extern void
-st_release_fp_variants( struct st_context *st,
-                        struct st_common_program *stfp );
+st_release_variants(struct st_context *st, struct st_program *p);
 
 extern void
-st_release_common_variants(struct st_context *st, struct st_common_program *p);
+st_release_program(struct st_context *st, struct st_program **p);
 
 extern void
 st_destroy_program_variants(struct st_context *st);
@@ -326,22 +327,25 @@ extern void
 st_finalize_nir_before_variants(struct nir_shader *nir);
 
 extern void
-st_prepare_vertex_program(struct st_common_program *stvp);
+st_prepare_vertex_program(struct st_program *stvp);
 
 extern void
 st_translate_stream_output_info(struct gl_program *prog);
 
 extern bool
 st_translate_vertex_program(struct st_context *st,
-                            struct st_common_program *stvp);
+                            struct st_program *stvp);
 
 extern bool
 st_translate_fragment_program(struct st_context *st,
-                              struct st_common_program *stfp);
+                              struct st_program *stfp);
 
 extern bool
 st_translate_common_program(struct st_context *st,
-                            struct st_common_program *stcp);
+                            struct st_program *stp);
+
+extern void
+st_serialize_nir(struct st_program *stp);
 
 extern void
 st_finalize_program(struct st_context *st, struct gl_program *prog);