draw: add vs/gs images support
[mesa.git] / src / gallium / auxiliary / draw / draw_llvm.h
index c40df1c1342b39bd837b869a69f4ef658c99ba53..914f783fd000209b9715a103528ce9548d9d0ec1 100644 (file)
@@ -49,11 +49,11 @@ struct draw_jit_texture
    uint32_t width;
    uint32_t height;
    uint32_t depth;
-   uint32_t first_level;
-   uint32_t last_level;
    const void *base;
    uint32_t row_stride[PIPE_MAX_TEXTURE_LEVELS];
    uint32_t img_stride[PIPE_MAX_TEXTURE_LEVELS];
+   uint32_t first_level;
+   uint32_t last_level;
    uint32_t mip_offsets[PIPE_MAX_TEXTURE_LEVELS];
 };
 
@@ -69,6 +69,11 @@ struct draw_sampler_static_state
    struct lp_static_texture_state texture_state;
 };
 
+struct draw_image_static_state
+{
+   struct lp_static_texture_state image_state;
+};
+
 
 struct draw_jit_sampler
 {
@@ -79,15 +84,25 @@ struct draw_jit_sampler
 };
 
 
+struct draw_jit_image
+{
+   uint32_t width;
+   uint32_t height;
+   uint32_t depth;
+   const void *base;
+   uint32_t row_stride;
+   uint32_t img_stride;
+};
+
 enum {
    DRAW_JIT_TEXTURE_WIDTH = 0,
    DRAW_JIT_TEXTURE_HEIGHT,
    DRAW_JIT_TEXTURE_DEPTH,
-   DRAW_JIT_TEXTURE_FIRST_LEVEL,
-   DRAW_JIT_TEXTURE_LAST_LEVEL,
    DRAW_JIT_TEXTURE_BASE,
    DRAW_JIT_TEXTURE_ROW_STRIDE,
    DRAW_JIT_TEXTURE_IMG_STRIDE,
+   DRAW_JIT_TEXTURE_FIRST_LEVEL,
+   DRAW_JIT_TEXTURE_LAST_LEVEL,
    DRAW_JIT_TEXTURE_MIP_OFFSETS,
    DRAW_JIT_TEXTURE_NUM_FIELDS  /* number of fields above */
 };
@@ -104,11 +119,20 @@ enum {
 
 enum {
    DRAW_JIT_VERTEX_VERTEX_ID = 0,
-   DRAW_JIT_VERTEX_CLIP_VERTEX,
    DRAW_JIT_VERTEX_CLIP_POS,
    DRAW_JIT_VERTEX_DATA
 };
 
+enum {
+   DRAW_JIT_IMAGE_WIDTH = 0,
+   DRAW_JIT_IMAGE_HEIGHT,
+   DRAW_JIT_IMAGE_DEPTH,
+   DRAW_JIT_IMAGE_BASE,
+   DRAW_JIT_IMAGE_ROW_STRIDE,
+   DRAW_JIT_IMAGE_IMG_STRIDE,
+   DRAW_JIT_IMAGE_NUM_FIELDS  /* number of fields above */
+};
+
 /**
  * This structure is passed directly to the generated vertex shader.
  *
@@ -129,6 +153,10 @@ struct draw_jit_context
 
    struct draw_jit_texture textures[PIPE_MAX_SHADER_SAMPLER_VIEWS];
    struct draw_jit_sampler samplers[PIPE_MAX_SAMPLERS];
+   struct draw_jit_image images[PIPE_MAX_SHADER_IMAGES];
+
+   const uint32_t *vs_ssbos[LP_MAX_TGSI_SHADER_BUFFERS];
+   int num_vs_ssbos[LP_MAX_TGSI_SHADER_BUFFERS];
 };
 
 enum {
@@ -138,6 +166,9 @@ enum {
    DRAW_JIT_CTX_VIEWPORT             = 3,
    DRAW_JIT_CTX_TEXTURES             = 4,
    DRAW_JIT_CTX_SAMPLERS             = 5,
+   DRAW_JIT_CTX_IMAGES               = 6,
+   DRAW_JIT_CTX_SSBOS                = 7,
+   DRAW_JIT_CTX_NUM_SSBOS            = 8,
    DRAW_JIT_CTX_NUM_FIELDS
 };
 
@@ -159,12 +190,19 @@ enum {
 #define draw_jit_context_samplers(_gallivm, _ptr) \
    lp_build_struct_get_ptr(_gallivm, _ptr, DRAW_JIT_CTX_SAMPLERS, "samplers")
 
+#define draw_jit_context_images(_gallivm, _ptr) \
+   lp_build_struct_get_ptr(_gallivm, _ptr, DRAW_JIT_CTX_IMAGES, "images")
+
+#define draw_jit_context_vs_ssbos(_gallivm, _ptr) \
+   lp_build_struct_get_ptr(_gallivm, _ptr, DRAW_JIT_CTX_SSBOS, "vs_ssbos")
+
+#define draw_jit_context_num_vs_ssbos(_gallivm, _ptr) \
+   lp_build_struct_get_ptr(_gallivm, _ptr, DRAW_JIT_CTX_NUM_SSBOS, "num_vs_ssbos")
+
+
 #define draw_jit_header_id(_gallivm, _ptr)              \
    lp_build_struct_get_ptr(_gallivm, _ptr, DRAW_JIT_VERTEX_VERTEX_ID, "id")
 
-#define draw_jit_header_clip_vertex(_gallivm, _ptr) \
-   lp_build_struct_get_ptr(_gallivm, _ptr, DRAW_JIT_VERTEX_CLIP_VERTEX, "clip_vertex")
-
 #define draw_jit_header_clip_pos(_gallivm, _ptr) \
    lp_build_struct_get_ptr(_gallivm, _ptr, DRAW_JIT_VERTEX_CLIP_POS, "clip_pos")
 
@@ -176,7 +214,7 @@ enum {
    lp_build_struct_get(_gallivm, _ptr, 0, "stride")
 
 #define draw_jit_vbuffer_offset(_gallivm, _ptr)         \
-   lp_build_struct_get(_gallivm, _ptr, 1, "buffer_offset")
+   lp_build_struct_get(_gallivm, _ptr, 2, "buffer_offset")
 
 enum {
    DRAW_JIT_DVBUFFER_MAP = 0,
@@ -213,10 +251,14 @@ struct draw_gs_jit_context
     * DRAW_JIT_CTX_SAMPLERS positions in the struct */
    struct draw_jit_texture textures[PIPE_MAX_SHADER_SAMPLER_VIEWS];
    struct draw_jit_sampler samplers[PIPE_MAX_SAMPLERS];
-   
+   struct draw_jit_image images[PIPE_MAX_SHADER_IMAGES];
+
    int **prim_lengths;
    int *emitted_vertices;
    int *emitted_prims;
+   const uint32_t *ssbos[LP_MAX_TGSI_SHADER_BUFFERS];
+   int num_ssbos[LP_MAX_TGSI_SHADER_BUFFERS];
+
 };
 
 enum {
@@ -230,10 +272,13 @@ enum {
     * VS ctx structure for sampling to work. */
    DRAW_GS_JIT_CTX_TEXTURES = DRAW_JIT_CTX_TEXTURES,
    DRAW_GS_JIT_CTX_SAMPLERS = DRAW_JIT_CTX_SAMPLERS,
-   DRAW_GS_JIT_CTX_PRIM_LENGTHS = 6,
-   DRAW_GS_JIT_CTX_EMITTED_VERTICES = 7,
-   DRAW_GS_JIT_CTX_EMITTED_PRIMS = 8,
-   DRAW_GS_JIT_CTX_NUM_FIELDS = 9
+   DRAW_GS_JIT_CTX_IMAGES = DRAW_JIT_CTX_IMAGES,
+   DRAW_GS_JIT_CTX_PRIM_LENGTHS = 7,
+   DRAW_GS_JIT_CTX_EMITTED_VERTICES = 8,
+   DRAW_GS_JIT_CTX_EMITTED_PRIMS = 9,
+   DRAW_GS_JIT_CTX_SSBOS = 10,
+   DRAW_GS_JIT_CTX_NUM_SSBOS = 11,
+   DRAW_GS_JIT_CTX_NUM_FIELDS = 12
 };
 
 #define draw_gs_jit_context_constants(_gallivm, _ptr) \
@@ -254,6 +299,9 @@ enum {
 #define draw_gs_jit_context_samplers(_gallivm, _ptr) \
    lp_build_struct_get_ptr(_gallivm, _ptr, DRAW_GS_JIT_CTX_SAMPLERS, "samplers")
 
+#define draw_gs_jit_context_images(_gallivm, _ptr)                      \
+   lp_build_struct_get_ptr(_gallivm, _ptr, DRAW_GS_JIT_CTX_IMAGES, "images")
+
 #define draw_gs_jit_prim_lengths(_gallivm, _ptr) \
    lp_build_struct_get(_gallivm, _ptr, DRAW_GS_JIT_CTX_PRIM_LENGTHS, "prim_lengths")
 
@@ -263,33 +311,24 @@ enum {
 #define draw_gs_jit_emitted_prims(_gallivm, _ptr) \
    lp_build_struct_get(_gallivm, _ptr, DRAW_GS_JIT_CTX_EMITTED_PRIMS, "emitted_prims")
 
+#define draw_gs_jit_context_ssbos(_gallivm, _ptr) \
+   lp_build_struct_get_ptr(_gallivm, _ptr, DRAW_GS_JIT_CTX_SSBOS, "ssbos")
 
+#define draw_gs_jit_context_num_ssbos(_gallivm, _ptr) \
+   lp_build_struct_get_ptr(_gallivm, _ptr, DRAW_GS_JIT_CTX_NUM_SSBOS, "num_ssbos")
 
-typedef int
+typedef boolean
 (*draw_jit_vert_func)(struct draw_jit_context *context,
                       struct vertex_header *io,
                       const struct draw_vertex_buffer vbuffers[PIPE_MAX_ATTRIBS],
-                      unsigned start,
                       unsigned count,
+                      unsigned start_or_maxelt,
                       unsigned stride,
                       struct pipe_vertex_buffer *vertex_buffers,
                       unsigned instance_id,
                       unsigned vertex_id_offset,
-                      unsigned start_instance);
-
-
-typedef int
-(*draw_jit_vert_func_elts)(struct draw_jit_context *context,
-                           struct vertex_header *io,
-                           const struct draw_vertex_buffer vbuffers[PIPE_MAX_ATTRIBS],
-                           const unsigned *fetch_elts,
-                           unsigned fetch_max_elt,
-                           unsigned fetch_count,
-                           unsigned stride,
-                           struct pipe_vertex_buffer *vertex_buffers,
-                           unsigned instance_id,
-                           unsigned vertex_id_offset,
-                           unsigned start_instance);
+                      unsigned start_instance,
+                      const unsigned *fetch_elts);
 
 
 typedef int
@@ -306,6 +345,7 @@ struct draw_llvm_variant_key
    unsigned nr_vertex_elements:8;
    unsigned nr_samplers:8;
    unsigned nr_sampler_views:8;
+   unsigned nr_images:8;
    unsigned clamp_vertex_color:1;
    unsigned clip_xy:1;
    unsigned clip_z:1;
@@ -315,12 +355,8 @@ struct draw_llvm_variant_key
    unsigned need_edgeflags:1;
    unsigned has_gs:1;
    unsigned num_outputs:8;
-   /*
-    * it is important there are no holes in this struct
-    * (and all padding gets zeroed).
-    */
    unsigned ucp_enable:PIPE_MAX_CLIP_PLANES;
-   unsigned pad1:24-PIPE_MAX_CLIP_PLANES;
+   /* note padding here - must use memset */
 
    /* Variable number of vertex elements:
     */
@@ -329,41 +365,50 @@ struct draw_llvm_variant_key
    /* Followed by variable number of samplers:
     */
 /*   struct draw_sampler_static_state sampler; */
+   /* Followed by variable number of images
+    */
 };
 
 struct draw_gs_llvm_variant_key
 {
    unsigned nr_samplers:8;
    unsigned nr_sampler_views:8;
+   unsigned nr_images:8;
    unsigned num_outputs:8;
+   /* note padding here - must use memset */
 
    struct draw_sampler_static_state samplers[1];
+   /* Followed by variable number of images.*/
 };
 
 #define DRAW_LLVM_MAX_VARIANT_KEY_SIZE \
    (sizeof(struct draw_llvm_variant_key) +     \
     PIPE_MAX_SHADER_SAMPLER_VIEWS * sizeof(struct draw_sampler_static_state) + \
+    PIPE_MAX_SHADER_IMAGES * sizeof(struct draw_image_static_state) + \
     (PIPE_MAX_ATTRIBS-1) * sizeof(struct pipe_vertex_element))
 
 #define DRAW_GS_LLVM_MAX_VARIANT_KEY_SIZE \
    (sizeof(struct draw_gs_llvm_variant_key) +  \
+    PIPE_MAX_SHADER_IMAGES * sizeof(struct draw_image_static_state) + \
     PIPE_MAX_SHADER_SAMPLER_VIEWS * sizeof(struct draw_sampler_static_state))
 
 
 static inline size_t
 draw_llvm_variant_key_size(unsigned nr_vertex_elements,
-                           unsigned nr_samplers)
+                           unsigned nr_samplers, unsigned nr_images)
 {
    return (sizeof(struct draw_llvm_variant_key) +
            nr_samplers * sizeof(struct draw_sampler_static_state) +
+           nr_images * sizeof(struct draw_image_static_state) +
            (nr_vertex_elements - 1) * sizeof(struct pipe_vertex_element));
 }
 
 
 static inline size_t
-draw_gs_llvm_variant_key_size(unsigned nr_samplers)
+draw_gs_llvm_variant_key_size(unsigned nr_samplers, unsigned nr_images)
 {
    return (sizeof(struct draw_gs_llvm_variant_key) +
+           (nr_images) * sizeof(struct draw_sampler_static_state) +
            (nr_samplers - 1) * sizeof(struct draw_sampler_static_state));
 }
 
@@ -375,6 +420,21 @@ draw_llvm_variant_key_samplers(struct draw_llvm_variant_key *key)
       &key->vertex_element[key->nr_vertex_elements];
 }
 
+static inline struct draw_image_static_state *
+draw_llvm_variant_key_images(struct draw_llvm_variant_key *key)
+{
+   struct draw_sampler_static_state *samplers = (struct draw_sampler_static_state *)
+      (&key->vertex_element[key->nr_vertex_elements]);
+   return (struct draw_image_static_state *)
+      &samplers[key->nr_samplers];
+}
+
+static inline struct draw_image_static_state *
+draw_gs_llvm_variant_key_images(struct draw_gs_llvm_variant_key *key)
+{
+   return (struct draw_image_static_state *)
+      &key->samplers[key->nr_samplers];
+}
 
 struct draw_llvm_variant_list_item
 {
@@ -400,9 +460,7 @@ struct draw_llvm_variant
    LLVMTypeRef vertex_header_ptr_type;
 
    LLVMValueRef function;
-   LLVMValueRef function_elts;
    draw_jit_vert_func jit_func;
-   draw_jit_vert_func_elts jit_func_elts;
 
    struct llvm_vertex_shader *shader;
 
@@ -529,12 +587,16 @@ draw_gs_llvm_dump_variant_key(struct draw_gs_llvm_variant_key *key);
 struct lp_build_sampler_soa *
 draw_llvm_sampler_soa_create(const struct draw_sampler_static_state *static_state);
 
+struct lp_build_image_soa *
+draw_llvm_image_soa_create(const struct draw_image_static_state *static_state);
+
 void
-draw_llvm_set_sampler_state(struct draw_context *draw, unsigned shader_stage);
+draw_llvm_set_sampler_state(struct draw_context *draw,
+                            enum pipe_shader_type shader_stage);
 
 void
 draw_llvm_set_mapped_texture(struct draw_context *draw,
-                             unsigned shader_stage,
+                             enum pipe_shader_type shader_stage,
                              unsigned sview_idx,
                              uint32_t width, uint32_t height, uint32_t depth,
                              uint32_t first_level, uint32_t last_level,
@@ -543,4 +605,12 @@ draw_llvm_set_mapped_texture(struct draw_context *draw,
                              uint32_t img_stride[PIPE_MAX_TEXTURE_LEVELS],
                              uint32_t mip_offsets[PIPE_MAX_TEXTURE_LEVELS]);
 
+void
+draw_llvm_set_mapped_image(struct draw_context *draw,
+                           enum pipe_shader_type shader_stage,
+                           unsigned idx,
+                           uint32_t width, uint32_t height, uint32_t depth,
+                           const void *base_ptr,
+                           uint32_t row_stride,
+                           uint32_t img_stride);
 #endif