Merge branch 'vulkan'
[mesa.git] / src / intel / vulkan / anv_private.h
index b112b457b992f7f989565041b12dd9a29d350cfc..ae2e08d2dfb405a36b19dfe42672ced9414281e7 100644 (file)
@@ -468,15 +468,13 @@ struct anv_state anv_state_stream_alloc(struct anv_state_stream *stream,
 struct anv_bo_pool {
    struct anv_device *device;
 
-   uint32_t bo_size;
-
-   void *free_list;
+   void *free_list[16];
 };
 
-void anv_bo_pool_init(struct anv_bo_pool *pool,
-                      struct anv_device *device, uint32_t block_size);
+void anv_bo_pool_init(struct anv_bo_pool *pool, struct anv_device *device);
 void anv_bo_pool_finish(struct anv_bo_pool *pool);
-VkResult anv_bo_pool_alloc(struct anv_bo_pool *pool, struct anv_bo *bo);
+VkResult anv_bo_pool_alloc(struct anv_bo_pool *pool, struct anv_bo *bo,
+                           uint32_t size);
 void anv_bo_pool_free(struct anv_bo_pool *pool, const struct anv_bo *bo);
 
 
@@ -548,6 +546,7 @@ struct anv_physical_device {
     uint64_t                                    aperture_size;
     struct brw_compiler *                       compiler;
     struct isl_device                           isl_dev;
+    int                                         cmd_parser_version;
 };
 
 struct anv_wsi_interaface;
@@ -607,6 +606,21 @@ struct anv_meta_state {
       VkDescriptorSetLayout                     ds_layout;
    } blit;
 
+   struct {
+      VkRenderPass render_pass;
+
+      VkPipelineLayout                          img_p_layout;
+      VkDescriptorSetLayout                     img_ds_layout;
+      VkPipelineLayout                          buf_p_layout;
+      VkDescriptorSetLayout                     buf_ds_layout;
+
+      /* Pipelines indexed by source and destination type.  See the
+       * blit2d_src_type and blit2d_dst_type enums in anv_meta_blit2d.c to
+       * see what these mean.
+       */
+      VkPipeline pipelines[2][3];
+   } blit2d;
+
    struct {
       /** Pipeline [i] resolves an image with 2^(i+1) samples.  */
       VkPipeline                                pipelines[MAX_SAMPLES_LOG2];
@@ -664,6 +678,7 @@ struct anv_device {
     struct isl_device                           isl_dev;
     int                                         context_id;
     int                                         fd;
+    bool                                        can_chain_batches;
 
     struct anv_bo_pool                          batch_bo_pool;
 
@@ -691,11 +706,6 @@ struct anv_device {
     pthread_mutex_t                             mutex;
 };
 
-VkResult gen7_init_device_state(struct anv_device *device);
-VkResult gen75_init_device_state(struct anv_device *device);
-VkResult gen8_init_device_state(struct anv_device *device);
-VkResult gen9_init_device_state(struct anv_device *device);
-
 void anv_device_get_cache_uuid(void *uuid);
 
 
@@ -809,6 +819,15 @@ __gen_combine_address(struct anv_batch *batch, void *location,
 #define __anv_cmd_length_bias(cmd) cmd ## _length_bias
 #define __anv_cmd_header(cmd) cmd ## _header
 #define __anv_cmd_pack(cmd) cmd ## _pack
+#define __anv_reg_num(reg) reg ## _num
+
+#define anv_pack_struct(dst, struc, ...) do {                              \
+      struct struc __template = {                                          \
+         __VA_ARGS__                                                       \
+      };                                                                   \
+      __anv_cmd_pack(struc)(NULL, dst, &__template);                       \
+      VG(VALGRIND_CHECK_MEM_IS_DEFINED(dst, __anv_cmd_length(struc) * 4)); \
+   } while (0)
 
 #define anv_batch_emit(batch, cmd, ...) do {                               \
       void *__dst = anv_batch_emit_dwords(batch, __anv_cmd_length(cmd));   \
@@ -995,11 +1014,16 @@ anv_descriptor_set_destroy(struct anv_device *device,
                            struct anv_descriptor_pool *pool,
                            struct anv_descriptor_set *set);
 
+#define ANV_DESCRIPTOR_SET_COLOR_ATTACHMENTS UINT16_MAX
+
 struct anv_pipeline_binding {
-   /* The descriptor set this surface corresponds to */
+   /* The descriptor set this surface corresponds to.  The special value of
+    * ANV_DESCRIPTOR_SET_COLOR_ATTACHMENTS indicates that the offset refers
+    * to a color attachment and not a regular descriptor.
+    */
    uint16_t set;
 
-   /* Offset into the descriptor set */
+   /* Offset into the descriptor set or attachment list. */
    uint16_t offset;
 };
 
@@ -1184,6 +1208,7 @@ struct anv_cmd_pool {
 enum anv_cmd_buffer_exec_mode {
    ANV_CMD_BUFFER_EXEC_MODE_PRIMARY,
    ANV_CMD_BUFFER_EXEC_MODE_EMIT,
+   ANV_CMD_BUFFER_EXEC_MODE_GROW_AND_EMIT,
    ANV_CMD_BUFFER_EXEC_MODE_CHAIN,
    ANV_CMD_BUFFER_EXEC_MODE_COPY_AND_CHAIN,
 };
@@ -1289,42 +1314,14 @@ anv_cmd_buffer_new_binding_table_block(struct anv_cmd_buffer *cmd_buffer);
 void gen8_cmd_buffer_emit_viewport(struct anv_cmd_buffer *cmd_buffer);
 void gen7_cmd_buffer_emit_scissor(struct anv_cmd_buffer *cmd_buffer);
 
-void gen7_cmd_buffer_emit_state_base_address(struct anv_cmd_buffer *cmd_buffer);
-void gen75_cmd_buffer_emit_state_base_address(struct anv_cmd_buffer *cmd_buffer);
-void gen8_cmd_buffer_emit_state_base_address(struct anv_cmd_buffer *cmd_buffer);
-void gen9_cmd_buffer_emit_state_base_address(struct anv_cmd_buffer *cmd_buffer);
-
 void anv_cmd_buffer_emit_state_base_address(struct anv_cmd_buffer *cmd_buffer);
 
 void anv_cmd_state_setup_attachments(struct anv_cmd_buffer *cmd_buffer,
                                      const VkRenderPassBeginInfo *info);
 
-void gen7_cmd_buffer_set_subpass(struct anv_cmd_buffer *cmd_buffer,
-                                   struct anv_subpass *subpass);
-void gen75_cmd_buffer_set_subpass(struct anv_cmd_buffer *cmd_buffer,
-                                  struct anv_subpass *subpass);
-void gen8_cmd_buffer_set_subpass(struct anv_cmd_buffer *cmd_buffer,
-                                   struct anv_subpass *subpass);
-void gen9_cmd_buffer_set_subpass(struct anv_cmd_buffer *cmd_buffer,
-                                   struct anv_subpass *subpass);
 void anv_cmd_buffer_set_subpass(struct anv_cmd_buffer *cmd_buffer,
                                   struct anv_subpass *subpass);
 
-void gen7_flush_pipeline_select_3d(struct anv_cmd_buffer *cmd_buffer);
-void gen75_flush_pipeline_select_3d(struct anv_cmd_buffer *cmd_buffer);
-void gen8_flush_pipeline_select_3d(struct anv_cmd_buffer *cmd_buffer);
-void gen9_flush_pipeline_select_3d(struct anv_cmd_buffer *cmd_buffer);
-
-void gen7_cmd_buffer_flush_state(struct anv_cmd_buffer *cmd_buffer);
-void gen75_cmd_buffer_flush_state(struct anv_cmd_buffer *cmd_buffer);
-void gen8_cmd_buffer_flush_state(struct anv_cmd_buffer *cmd_buffer);
-void gen9_cmd_buffer_flush_state(struct anv_cmd_buffer *cmd_buffer);
-
-void gen7_cmd_buffer_flush_compute_state(struct anv_cmd_buffer *cmd_buffer);
-void gen75_cmd_buffer_flush_compute_state(struct anv_cmd_buffer *cmd_buffer);
-void gen8_cmd_buffer_flush_compute_state(struct anv_cmd_buffer *cmd_buffer);
-void gen9_cmd_buffer_flush_compute_state(struct anv_cmd_buffer *cmd_buffer);
-
 struct anv_state
 anv_cmd_buffer_push_constants(struct anv_cmd_buffer *cmd_buffer,
                               gl_shader_stage stage);
@@ -1391,9 +1388,11 @@ struct anv_pipeline_bind_map {
    uint32_t surface_count;
    uint32_t sampler_count;
    uint32_t image_count;
+   uint32_t attachment_count;
 
    struct anv_pipeline_binding *                surface_to_descriptor;
    struct anv_pipeline_binding *                sampler_to_descriptor;
+   uint32_t *                                   surface_to_attachment;
 };
 
 struct anv_pipeline {
@@ -1409,7 +1408,6 @@ struct anv_pipeline {
 
    bool                                         use_repclear;
 
-   bool                                         writes_point_size;
    const struct brw_stage_prog_data *           prog_data[MESA_SHADER_STAGES];
    uint32_t                                     scratch_start[MESA_SHADER_STAGES];
    uint32_t                                     total_scratch;
@@ -1490,8 +1488,6 @@ struct anv_graphics_pipeline_create_info {
    int8_t color_attachment_count;
 
    bool                                         use_repclear;
-   bool                                         disable_viewport;
-   bool                                         disable_scissor;
    bool                                         disable_vs;
    bool                                         use_rectlist;
 };
@@ -1519,62 +1515,6 @@ anv_graphics_pipeline_create(VkDevice device,
                              const VkAllocationCallbacks *alloc,
                              VkPipeline *pPipeline);
 
-VkResult
-gen7_graphics_pipeline_create(VkDevice _device,
-                              struct anv_pipeline_cache *cache,
-                              const VkGraphicsPipelineCreateInfo *pCreateInfo,
-                              const struct anv_graphics_pipeline_create_info *extra,
-                              const VkAllocationCallbacks *alloc,
-                              VkPipeline *pPipeline);
-
-VkResult
-gen75_graphics_pipeline_create(VkDevice _device,
-                               struct anv_pipeline_cache *cache,
-                               const VkGraphicsPipelineCreateInfo *pCreateInfo,
-                               const struct anv_graphics_pipeline_create_info *extra,
-                               const VkAllocationCallbacks *alloc,
-                               VkPipeline *pPipeline);
-
-VkResult
-gen8_graphics_pipeline_create(VkDevice _device,
-                              struct anv_pipeline_cache *cache,
-                              const VkGraphicsPipelineCreateInfo *pCreateInfo,
-                              const struct anv_graphics_pipeline_create_info *extra,
-                              const VkAllocationCallbacks *alloc,
-                              VkPipeline *pPipeline);
-VkResult
-gen9_graphics_pipeline_create(VkDevice _device,
-                              struct anv_pipeline_cache *cache,
-                              const VkGraphicsPipelineCreateInfo *pCreateInfo,
-                              const struct anv_graphics_pipeline_create_info *extra,
-                              const VkAllocationCallbacks *alloc,
-                              VkPipeline *pPipeline);
-VkResult
-gen7_compute_pipeline_create(VkDevice _device,
-                             struct anv_pipeline_cache *cache,
-                             const VkComputePipelineCreateInfo *pCreateInfo,
-                             const VkAllocationCallbacks *alloc,
-                             VkPipeline *pPipeline);
-VkResult
-gen75_compute_pipeline_create(VkDevice _device,
-                              struct anv_pipeline_cache *cache,
-                              const VkComputePipelineCreateInfo *pCreateInfo,
-                              const VkAllocationCallbacks *alloc,
-                              VkPipeline *pPipeline);
-
-VkResult
-gen8_compute_pipeline_create(VkDevice _device,
-                             struct anv_pipeline_cache *cache,
-                             const VkComputePipelineCreateInfo *pCreateInfo,
-                             const VkAllocationCallbacks *alloc,
-                             VkPipeline *pPipeline);
-VkResult
-gen9_compute_pipeline_create(VkDevice _device,
-                             struct anv_pipeline_cache *cache,
-                             const VkComputePipelineCreateInfo *pCreateInfo,
-                             const VkAllocationCallbacks *alloc,
-                             VkPipeline *pPipeline);
-
 struct anv_format_swizzle {
    unsigned r:2;
    unsigned g:2;
@@ -1725,35 +1665,8 @@ void anv_image_view_init(struct anv_image_view *view,
                          struct anv_device *device,
                          const VkImageViewCreateInfo* pCreateInfo,
                          struct anv_cmd_buffer *cmd_buffer,
-                         uint32_t offset,
                          VkImageUsageFlags usage_mask);
 
-void
-anv_fill_image_surface_state(struct anv_device *device, struct anv_state state,
-                             struct anv_image_view *iview,
-                             const VkImageViewCreateInfo *pCreateInfo,
-                             VkImageUsageFlagBits usage);
-void
-gen7_fill_image_surface_state(struct anv_device *device, void *state_map,
-                              struct anv_image_view *iview,
-                              const VkImageViewCreateInfo *pCreateInfo,
-                              VkImageUsageFlagBits usage);
-void
-gen75_fill_image_surface_state(struct anv_device *device, void *state_map,
-                               struct anv_image_view *iview,
-                               const VkImageViewCreateInfo *pCreateInfo,
-                               VkImageUsageFlagBits usage);
-void
-gen8_fill_image_surface_state(struct anv_device *device, void *state_map,
-                              struct anv_image_view *iview,
-                              const VkImageViewCreateInfo *pCreateInfo,
-                              VkImageUsageFlagBits usage);
-void
-gen9_fill_image_surface_state(struct anv_device *device, void *state_map,
-                              struct anv_image_view *iview,
-                              const VkImageViewCreateInfo *pCreateInfo,
-                              VkImageUsageFlagBits usage);
-
 struct anv_buffer_view {
    enum isl_format format; /**< VkBufferViewCreateInfo::format */
    struct anv_bo *bo;
@@ -1766,28 +1679,53 @@ struct anv_buffer_view {
    struct brw_image_param storage_image_param;
 };
 
+void anv_buffer_view_init(struct anv_buffer_view *view,
+                          struct anv_device *device,
+                          const VkBufferViewCreateInfo* pCreateInfo,
+                          struct anv_cmd_buffer *cmd_buffer);
+
 const struct anv_format *
 anv_format_for_descriptor_type(VkDescriptorType type);
 
+static inline struct VkExtent3D
+anv_sanitize_image_extent(const VkImageType imageType,
+                          const struct VkExtent3D imageExtent)
+{
+   switch (imageType) {
+   case VK_IMAGE_TYPE_1D:
+      return (VkExtent3D) { imageExtent.width, 1, 1 };
+   case VK_IMAGE_TYPE_2D:
+      return (VkExtent3D) { imageExtent.width, imageExtent.height, 1 };
+   case VK_IMAGE_TYPE_3D:
+      return imageExtent;
+   default:
+      unreachable("invalid image type");
+   }
+}
+
+static inline struct VkOffset3D
+anv_sanitize_image_offset(const VkImageType imageType,
+                          const struct VkOffset3D imageOffset)
+{
+   switch (imageType) {
+   case VK_IMAGE_TYPE_1D:
+      return (VkOffset3D) { imageOffset.x, 0, 0 };
+   case VK_IMAGE_TYPE_2D:
+      return (VkOffset3D) { imageOffset.x, imageOffset.y, 0 };
+   case VK_IMAGE_TYPE_3D:
+      return imageOffset;
+   default:
+      unreachable("invalid image type");
+   }
+}
+
+
 void anv_fill_buffer_surface_state(struct anv_device *device,
                                    struct anv_state state,
                                    enum isl_format format,
                                    uint32_t offset, uint32_t range,
                                    uint32_t stride);
 
-void gen7_fill_buffer_surface_state(void *state, enum isl_format format,
-                                    uint32_t offset, uint32_t range,
-                                    uint32_t stride);
-void gen75_fill_buffer_surface_state(void *state, enum isl_format format,
-                                     uint32_t offset, uint32_t range,
-                                     uint32_t stride);
-void gen8_fill_buffer_surface_state(void *state, enum isl_format format,
-                                    uint32_t offset, uint32_t range,
-                                    uint32_t stride);
-void gen9_fill_buffer_surface_state(void *state, enum isl_format format,
-                                    uint32_t offset, uint32_t range,
-                                    uint32_t stride);
-
 void anv_image_view_fill_image_param(struct anv_device *device,
                                      struct anv_image_view *view,
                                      struct brw_image_param *param);
@@ -1930,6 +1868,24 @@ ANV_DEFINE_STRUCT_CASTS(anv_common, VkMemoryBarrier)
 ANV_DEFINE_STRUCT_CASTS(anv_common, VkBufferMemoryBarrier)
 ANV_DEFINE_STRUCT_CASTS(anv_common, VkImageMemoryBarrier)
 
+/* Gen-specific function declarations */
+#ifdef genX
+#  include "anv_genX.h"
+#else
+#  define genX(x) gen7_##x
+#  include "anv_genX.h"
+#  undef genX
+#  define genX(x) gen75_##x
+#  include "anv_genX.h"
+#  undef genX
+#  define genX(x) gen8_##x
+#  include "anv_genX.h"
+#  undef genX
+#  define genX(x) gen9_##x
+#  include "anv_genX.h"
+#  undef genX
+#endif
+
 #ifdef __cplusplus
 }
 #endif