anv: Only include the pack headers where needed
[mesa.git] / src / vulkan / anv_private.h
index bc747fcd27c8d29f275ba292110f44deb4a838d9..a8ed5e8a7e266e18d3f3962b390a697204529ff1 100644 (file)
 #define VK_PROTOTYPES
 #include <vulkan/vulkan.h>
 #include <vulkan/vulkan_intel.h>
-#include <vulkan/vk_wsi_swapchain.h>
-#include <vulkan/vk_wsi_device_swapchain.h>
+#include <vulkan/vk_ext_khr_swapchain.h>
+#include <vulkan/vk_ext_khr_device_swapchain.h>
 
 #include "anv_entrypoints.h"
-
 #include "brw_context.h"
+#include "isl.h"
 
 #ifdef __cplusplus
 extern "C" {
@@ -115,6 +115,11 @@ anv_clear_mask(uint32_t *inout_mask, uint32_t clear_mask)
         (b) = __builtin_ffs(__dword) - 1, __dword;      \
         __dword &= ~(1 << (b)))
 
+#define typed_memcpy(dest, src, count) ({ \
+   static_assert(sizeof(*src) == sizeof(*dest), ""); \
+   memcpy((dest), (src), (count) * sizeof(*(src))); \
+})
+
 /* Define no kernel as 1, since that's an illegal offset for a kernel */
 #define NO_KERNEL 1
 
@@ -159,6 +164,16 @@ void anv_loge_v(const char *format, va_list va);
 #define anv_assert(x)
 #endif
 
+/**
+ * If a block of code is annotated with anv_validate, then the block runs only
+ * in debug builds.
+ */
+#ifdef DEBUG
+#define anv_validate if (1)
+#else
+#define anv_validate if (0)
+#endif
+
 void anv_abortf(const char *format, ...) anv_noreturn anv_printflike(1, 2);
 void anv_abortfv(const char *format, va_list va) anv_noreturn;
 
@@ -412,8 +427,13 @@ struct anv_physical_device {
     const char *                                name;
     const struct brw_device_info *              info;
     uint64_t                                    aperture_size;
+    struct brw_compiler *                       compiler;
+    struct isl_device                           isl_dev;
 };
 
+bool anv_is_scalar_shader_stage(const struct brw_compiler *compiler,
+                                VkShaderStage stage);
+
 struct anv_instance {
     VK_LOADER_DATA                              _loader_data;
 
@@ -421,10 +441,10 @@ struct anv_instance {
     PFN_vkAllocFunction                         pfnAlloc;
     PFN_vkFreeFunction                          pfnFree;
     uint32_t                                    apiVersion;
-    uint32_t                                    physicalDeviceCount;
+    int                                         physicalDeviceCount;
     struct anv_physical_device                  physicalDevice;
 
-    struct anv_wsi_implementation *             wsi_impl[VK_PLATFORM_NUM_WSI];
+    struct anv_wsi_implementation *             wsi_impl[VK_PLATFORM_NUM_KHR];
 };
 
 VkResult anv_init_wsi(struct anv_instance *instance);
@@ -432,10 +452,15 @@ void anv_finish_wsi(struct anv_instance *instance);
 
 struct anv_meta_state {
    struct {
-      VkPipeline                                pipeline;
+      struct anv_pipeline *color_pipeline;
+      struct anv_pipeline *depth_only_pipeline;
+      struct anv_pipeline *stencil_only_pipeline;
+      struct anv_pipeline *depthstencil_pipeline;
    } clear;
 
    struct {
+      VkRenderPass render_pass;
+
       /** Pipeline that blits from a 2D image. */
       VkPipeline pipeline_2d_src;
 
@@ -445,12 +470,6 @@ struct anv_meta_state {
       VkPipelineLayout                          pipeline_layout;
       VkDescriptorSetLayout                     ds_layout;
    } blit;
-
-   struct {
-      VkDynamicRasterState                      rs_state;
-      VkDynamicColorBlendState                  cb_state;
-      VkDynamicDepthStencilState                ds_state;
-   } shared;
 };
 
 struct anv_queue {
@@ -459,20 +478,6 @@ struct anv_queue {
     struct anv_device *                         device;
 
     struct anv_state_pool *                     pool;
-
-    /**
-     * Serial number of the most recently completed batch executed on the
-     * engine.
-     */
-    struct anv_state                            completed_serial;
-
-    /**
-     * The next batch submitted to the engine will be assigned this serial
-     * number.
-     */
-    uint32_t                                    next_serial;
-
-    uint32_t                                    last_collected_serial;
 };
 
 struct anv_device {
@@ -481,6 +486,7 @@ struct anv_device {
     struct anv_instance *                       instance;
     uint32_t                                    chipset_id;
     struct brw_device_info                      info;
+    struct isl_device                           isl_dev;
     int                                         context_id;
     int                                         fd;
 
@@ -493,6 +499,8 @@ struct anv_device {
     struct anv_block_pool                       surface_state_block_pool;
     struct anv_state_pool                       surface_state_pool;
 
+    struct anv_bo                               workaround_bo;
+
     struct anv_meta_state                       meta_state;
 
     struct anv_state                            border_colors;
@@ -501,7 +509,6 @@ struct anv_device {
 
     struct anv_block_pool                       scratch_block_pool;
 
-    struct anv_compiler *                       compiler;
     pthread_mutex_t                             mutex;
 };
 
@@ -620,11 +627,6 @@ __gen_combine_address(struct anv_batch *batch, void *location,
    }
 }
 
-#include "gen7_pack.h"
-#include "gen75_pack.h"
-#undef GEN8_3DSTATE_MULTISAMPLE
-#include "gen8_pack.h"
-
 #define anv_batch_emit(batch, cmd, ...) do {                            \
       void *__dst = anv_batch_emit_dwords(batch, cmd ## _length);       \
       struct cmd __template = {                                         \
@@ -657,11 +659,11 @@ __gen_combine_address(struct anv_batch *batch, void *location,
       VG(VALGRIND_CHECK_MEM_IS_DEFINED(dw, ARRAY_SIZE(dwords0) * 4));\
    } while (0)
 
-static const struct GEN7_MEMORY_OBJECT_CONTROL_STATE GEN7_MOCS = {
-   .GraphicsDataTypeGFDT                        = 0,
-   .LLCCacheabilityControlLLCCC                 = 0,
-   .L3CacheabilityControlL3CC                   = 1
-};
+#define GEN7_MOCS (struct GEN7_MEMORY_OBJECT_CONTROL_STATE) {  \
+   .GraphicsDataTypeGFDT                        = 0,           \
+   .LLCCacheabilityControlLLCCC                 = 0,           \
+   .L3CacheabilityControlL3CC                   = 1,           \
+}
 
 #define GEN8_MOCS {                                     \
       .MemoryTypeLLCeLLCCacheabilityControl = WB,       \
@@ -675,65 +677,76 @@ struct anv_device_memory {
    void *                                       map;
 };
 
-struct anv_dynamic_vp_state {
-   struct anv_state sf_clip_vp;
-   struct anv_state cc_vp;
-   struct anv_state scissor;
+/**
+ * Header for Vertex URB Entry (VUE)
+ */
+struct anv_vue_header {
+   uint32_t Reserved;
+   uint32_t RTAIndex; /* RenderTargetArrayIndex */
+   uint32_t ViewportIndex;
+   float PointWidth;
 };
 
-struct anv_dynamic_rs_state {
-   struct {
-      uint32_t sf[GEN7_3DSTATE_SF_length];
-   } gen7;
+struct anv_descriptor_set_binding_layout {
+   /* Number of array elements in this binding */
+   uint16_t array_size;
 
-   struct {
-      uint32_t sf[GEN8_3DSTATE_SF_length];
-      uint32_t raster[GEN8_3DSTATE_RASTER_length];
-   } gen8;
-};
+   /* Index into the flattend descriptor set */
+   uint16_t descriptor_index;
 
-struct anv_dynamic_ds_state {
-   struct {
-      uint32_t depth_stencil_state[GEN7_DEPTH_STENCIL_STATE_length];
-      uint32_t color_calc_state[GEN8_COLOR_CALC_STATE_length];
-   } gen7;
+   /* Index into the dynamic state array for a dynamic buffer */
+   int16_t dynamic_offset_index;
 
    struct {
-      uint32_t wm_depth_stencil[GEN8_3DSTATE_WM_DEPTH_STENCIL_length];
-      uint32_t color_calc_state[GEN8_COLOR_CALC_STATE_length];
-   } gen8;
-};
-
-struct anv_dynamic_cb_state {
-   uint32_t color_calc_state[GEN8_COLOR_CALC_STATE_length];
+      /* Index into the binding table for the associated surface */
+      int16_t surface_index;
 
-};
+      /* Index into the sampler table for the associated sampler */
+      int16_t sampler_index;
+   } stage[VK_SHADER_STAGE_NUM];
 
-struct anv_descriptor_slot {
-   int8_t dynamic_slot;
-   uint8_t index;
+   /* Immutable samplers (or NULL if no immutable samplers) */
+   struct anv_sampler **immutable_samplers;
 };
 
 struct anv_descriptor_set_layout {
-   struct {
-      uint32_t surface_count;
-      struct anv_descriptor_slot *surface_start;
-      uint32_t sampler_count;
-      struct anv_descriptor_slot *sampler_start;
-   } stage[VK_SHADER_STAGE_NUM];
+   /* Number of bindings in this descriptor set */
+   uint16_t binding_count;
+
+   /* Total size of the descriptor set with room for all array entries */
+   uint16_t size;
 
-   uint32_t count;
-   uint32_t num_dynamic_buffers;
-   VkShaderStageFlags shader_stages;
-   struct anv_descriptor_slot entries[0];
+   /* Shader stages affected by this descriptor set */
+   uint16_t shader_stages;
+
+   /* Number of dynamic offsets used by this descriptor set */
+   uint16_t dynamic_offset_count;
+
+   /* Bindings in this descriptor set */
+   struct anv_descriptor_set_binding_layout binding[0];
 };
 
 struct anv_descriptor {
-   struct anv_sampler *sampler;
-   struct anv_surface_view *view;
+   VkDescriptorType type;
+
+   union {
+      struct {
+         union {
+            struct anv_image_view *image_view;
+         };
+         struct anv_sampler *sampler;
+      };
+
+      struct {
+         struct anv_buffer *buffer;
+         uint64_t offset;
+         uint64_t range;
+      };
+   };
 };
 
 struct anv_descriptor_set {
+   const struct anv_descriptor_set_layout *layout;
    struct anv_descriptor descriptors[0];
 };
 
@@ -746,13 +759,23 @@ void
 anv_descriptor_set_destroy(struct anv_device *device,
                            struct anv_descriptor_set *set);
 
-#define MAX_VBS   32
-#define MAX_SETS   8
-#define MAX_RTS    8
+#define MAX_VBS         32
+#define MAX_SETS         8
+#define MAX_RTS          8
+#define MAX_VIEWPORTS   16
+#define MAX_SCISSORS    16
 #define MAX_PUSH_CONSTANTS_SIZE 128
 #define MAX_DYNAMIC_BUFFERS 16
 #define MAX_IMAGES 8
 
+struct anv_pipeline_binding {
+   /* The descriptor set this surface corresponds to */
+   uint16_t set;
+
+   /* Offset into the descriptor set */
+   uint16_t offset;
+};
+
 struct anv_pipeline_layout {
    struct {
       struct anv_descriptor_set_layout *layout;
@@ -768,8 +791,12 @@ struct anv_pipeline_layout {
    struct {
       bool has_dynamic_offsets;
       uint32_t surface_count;
+      struct anv_pipeline_binding *surface_to_descriptor;
       uint32_t sampler_count;
+      struct anv_pipeline_binding *sampler_to_descriptor;
    } stage[VK_SHADER_STAGE_NUM];
+
+   struct anv_pipeline_binding entries[0];
 };
 
 struct anv_buffer {
@@ -778,26 +805,30 @@ struct anv_buffer {
 
    /* Set when bound */
    struct anv_bo *                              bo;
-   VkDeviceSize                                 offset;   
+   VkDeviceSize                                 offset;
 };
 
-#define ANV_CMD_BUFFER_PIPELINE_DIRTY           (1 << 0)
-#define ANV_CMD_BUFFER_RS_DIRTY                 (1 << 2)
-#define ANV_CMD_BUFFER_DS_DIRTY                 (1 << 3)
-#define ANV_CMD_BUFFER_CB_DIRTY                 (1 << 4)
-#define ANV_CMD_BUFFER_VP_DIRTY                 (1 << 5)
-#define ANV_CMD_BUFFER_INDEX_BUFFER_DIRTY       (1 << 6)
+enum anv_cmd_dirty_bits {
+   ANV_CMD_DIRTY_DYNAMIC_VIEWPORT                  = 1 << 0, /* VK_DYNAMIC_STATE_VIEWPORT */
+   ANV_CMD_DIRTY_DYNAMIC_SCISSOR                   = 1 << 1, /* VK_DYNAMIC_STATE_SCISSOR */
+   ANV_CMD_DIRTY_DYNAMIC_LINE_WIDTH                = 1 << 2, /* VK_DYNAMIC_STATE_LINE_WIDTH */
+   ANV_CMD_DIRTY_DYNAMIC_DEPTH_BIAS                = 1 << 3, /* VK_DYNAMIC_STATE_DEPTH_BIAS */
+   ANV_CMD_DIRTY_DYNAMIC_BLEND_CONSTANTS           = 1 << 4, /* VK_DYNAMIC_STATE_BLEND_CONSTANTS */
+   ANV_CMD_DIRTY_DYNAMIC_DEPTH_BOUNDS              = 1 << 5, /* VK_DYNAMIC_STATE_DEPTH_BOUNDS */
+   ANV_CMD_DIRTY_DYNAMIC_STENCIL_COMPARE_MASK      = 1 << 6, /* VK_DYNAMIC_STATE_STENCIL_COMPARE_MASK */
+   ANV_CMD_DIRTY_DYNAMIC_STENCIL_WRITE_MASK        = 1 << 7, /* VK_DYNAMIC_STATE_STENCIL_WRITE_MASK */
+   ANV_CMD_DIRTY_DYNAMIC_STENCIL_REFERENCE         = 1 << 8, /* VK_DYNAMIC_STATE_STENCIL_REFERENCE */
+   ANV_CMD_DIRTY_DYNAMIC_ALL                       = (1 << 9) - 1,
+   ANV_CMD_DIRTY_PIPELINE                          = 1 << 9,
+   ANV_CMD_DIRTY_INDEX_BUFFER                      = 1 << 10,
+};
+typedef uint32_t anv_cmd_dirty_mask_t;
 
 struct anv_vertex_binding {
    struct anv_buffer *                          buffer;
    VkDeviceSize                                 offset;
 };
 
-struct anv_descriptor_set_binding {
-   struct anv_descriptor_set *                  set;
-   uint32_t                                     dynamic_offsets[128];
-};
-
 struct anv_push_constants {
    /* Current allocated size of this push constants data structure.
     * Because a decent chunk of it may not be used (images on SKL, for
@@ -815,19 +846,70 @@ struct anv_push_constants {
    uint32_t base_vertex;
    uint32_t base_instance;
 
-   /* Offsets for dynamically bound buffers */
-   uint32_t dynamic_offsets[MAX_DYNAMIC_BUFFERS];
+   /* Offsets and ranges for dynamically bound buffers */
+   struct {
+      uint32_t offset;
+      uint32_t range;
+   } dynamic[MAX_DYNAMIC_BUFFERS];
 
    /* Image data for image_load_store on pre-SKL */
    struct brw_image_param images[MAX_IMAGES];
 };
 
+struct anv_dynamic_state {
+   struct {
+      uint32_t                                  count;
+      VkViewport                                viewports[MAX_VIEWPORTS];
+   } viewport;
+
+   struct {
+      uint32_t                                  count;
+      VkRect2D                                  scissors[MAX_SCISSORS];
+   } scissor;
+
+   float                                        line_width;
+
+   struct {
+      float                                     bias;
+      float                                     clamp;
+      float                                     slope_scaled;
+   } depth_bias;
+
+   float                                        blend_constants[4];
+
+   struct {
+      float                                     min;
+      float                                     max;
+   } depth_bounds;
+
+   struct {
+      uint32_t                                  front;
+      uint32_t                                  back;
+   } stencil_compare_mask;
+
+   struct {
+      uint32_t                                  front;
+      uint32_t                                  back;
+   } stencil_write_mask;
+
+   struct {
+      uint32_t                                  front;
+      uint32_t                                  back;
+   } stencil_reference;
+};
+
+extern const struct anv_dynamic_state default_dynamic_state;
+
+void anv_dynamic_state_copy(struct anv_dynamic_state *dest,
+                            const struct anv_dynamic_state *src,
+                            uint32_t copy_mask);
+
 /** State required while building cmd buffer */
 struct anv_cmd_state {
    uint32_t                                     current_pipeline;
    uint32_t                                     vb_dirty;
-   uint32_t                                     dirty;
-   uint32_t                                     compute_dirty;
+   anv_cmd_dirty_mask_t                         dirty;
+   anv_cmd_dirty_mask_t                         compute_dirty;
    VkShaderStageFlags                           descriptors_dirty;
    VkShaderStageFlags                           push_constants_dirty;
    uint32_t                                     scratch_size;
@@ -836,14 +918,11 @@ struct anv_cmd_state {
    struct anv_framebuffer *                     framebuffer;
    struct anv_render_pass *                     pass;
    struct anv_subpass *                         subpass;
-   struct anv_dynamic_rs_state *                rs_state;
-   struct anv_dynamic_ds_state *                ds_state;
-   struct anv_dynamic_vp_state *                vp_state;
-   struct anv_dynamic_cb_state *                cb_state;
-   uint32_t                                     state_vf[GEN8_3DSTATE_VF_length];
+   uint32_t                                     state_vf[2];
    struct anv_vertex_binding                    vertex_bindings[MAX_VBS];
-   struct anv_descriptor_set_binding            descriptors[MAX_SETS];
+   struct anv_descriptor_set *                  descriptors[MAX_SETS];
    struct anv_push_constants *                  push_constants[VK_SHADER_STAGE_NUM];
+   struct anv_dynamic_state                     dynamic;
 
    struct {
       struct anv_buffer *                       index_buffer;
@@ -938,7 +1017,7 @@ VkResult anv_cmd_buffer_emit_binding_table(struct anv_cmd_buffer *cmd_buffer,
                                            unsigned stage, struct anv_state *bt_state);
 VkResult anv_cmd_buffer_emit_samplers(struct anv_cmd_buffer *cmd_buffer,
                                       unsigned stage, struct anv_state *state);
-void anv_flush_descriptor_sets(struct anv_cmd_buffer *cmd_buffer);
+void gen7_cmd_buffer_flush_descriptor_sets(struct anv_cmd_buffer *cmd_buffer);
 
 struct anv_state anv_cmd_buffer_emit_dynamic(struct anv_cmd_buffer *cmd_buffer,
                                              uint32_t *a, uint32_t dwords,
@@ -955,12 +1034,17 @@ struct anv_state
 anv_cmd_buffer_alloc_binding_table(struct anv_cmd_buffer *cmd_buffer,
                                    uint32_t entries, uint32_t *state_offset);
 struct anv_state
+anv_cmd_buffer_alloc_surface_state(struct anv_cmd_buffer *cmd_buffer);
+struct anv_state
 anv_cmd_buffer_alloc_dynamic_state(struct anv_cmd_buffer *cmd_buffer,
                                    uint32_t size, uint32_t alignment);
 
 VkResult
 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 gen8_cmd_buffer_emit_state_base_address(struct anv_cmd_buffer *cmd_buffer);
 
@@ -982,7 +1066,7 @@ anv_cmd_buffer_push_constants(struct anv_cmd_buffer *cmd_buffer,
 void anv_cmd_buffer_clear_attachments(struct anv_cmd_buffer *cmd_buffer,
                                       struct anv_render_pass *pass,
                                       const VkClearValue *clear_values);
-const struct anv_depth_stencil_view *
+const struct anv_image_view *
 anv_cmd_buffer_get_depth_stencil_view(const struct anv_cmd_buffer *cmd_buffer);
 
 void anv_cmd_buffer_dump(struct anv_cmd_buffer *cmd_buffer);
@@ -1011,9 +1095,11 @@ struct anv_shader {
 struct anv_pipeline {
    struct anv_device *                          device;
    struct anv_batch                             batch;
-   uint32_t                                     batch_data[256];
+   uint32_t                                     batch_data[512];
    struct anv_reloc_list                        batch_relocs;
-   struct anv_shader *                          shaders[VK_SHADER_STAGE_NUM];
+   uint32_t                                     dynamic_state_mask;
+   struct anv_dynamic_state                     dynamic_state;
+
    struct anv_pipeline_layout *                 layout;
    bool                                         use_repclear;
 
@@ -1059,15 +1145,15 @@ struct anv_pipeline {
    uint32_t                                     cs_right_mask;
 
    struct {
-      uint32_t                                  sf[GEN7_3DSTATE_SF_length];
-      uint32_t                                  depth_stencil_state[GEN7_DEPTH_STENCIL_STATE_length];
+      uint32_t                                  sf[7];
+      uint32_t                                  depth_stencil_state[3];
    } gen7;
 
    struct {
-      uint32_t                                  sf[GEN8_3DSTATE_SF_length];
-      uint32_t                                  vf[GEN8_3DSTATE_VF_length];
-      uint32_t                                  raster[GEN8_3DSTATE_RASTER_length];
-      uint32_t                                  wm_depth_stencil[GEN8_3DSTATE_WM_DEPTH_STENCIL_length];
+      uint32_t                                  sf[4];
+      uint32_t                                  vf[2];
+      uint32_t                                  raster[5];
+      uint32_t                                  wm_depth_stencil[3];
    } gen8;
 };
 
@@ -1084,6 +1170,11 @@ anv_pipeline_init(struct anv_pipeline *pipeline, struct anv_device *device,
                   const VkGraphicsPipelineCreateInfo *pCreateInfo,
                   const struct anv_graphics_pipeline_create_info *extra);
 
+VkResult
+anv_pipeline_compile_cs(struct anv_pipeline *pipeline,
+                        const VkComputePipelineCreateInfo *info,
+                        struct anv_shader *shader);
+
 VkResult
 anv_graphics_pipeline_create(VkDevice device,
                              const VkGraphicsPipelineCreateInfo *pCreateInfo,
@@ -1111,16 +1202,11 @@ gen8_compute_pipeline_create(VkDevice _device,
                              const VkComputePipelineCreateInfo *pCreateInfo,
                              VkPipeline *pPipeline);
 
-struct anv_compiler *anv_compiler_create(struct anv_device *device);
-void anv_compiler_destroy(struct anv_compiler *compiler);
-int anv_compiler_run(struct anv_compiler *compiler, struct anv_pipeline *pipeline);
-void anv_compiler_free(struct anv_pipeline *pipeline);
-
 struct anv_format {
    const VkFormat vk_format;
    const char *name;
-   uint16_t surface_format; /**< RENDER_SURFACE_STATE.SurfaceFormat */
-   uint8_t cpp; /**< Bytes-per-pixel of anv_format::surface_format. */
+   enum isl_format surface_format; /**< RENDER_SURFACE_STATE.SurfaceFormat */
+   const struct isl_format_layout *isl_layout;
    uint8_t num_channels;
    uint16_t depth_format; /**< 3DSTATE_DEPTH_BUFFER.SurfaceFormat */
    bool has_stencil;
@@ -1181,7 +1267,7 @@ struct anv_surface {
    uint8_t v_align; /**< RENDER_SURFACE_STATE.SurfaceVerticalAlignment */
    /** \} */
 
-   uint8_t tile_mode; /**< RENDER_SURFACE_STATE.TileMode */
+   enum isl_tiling tiling;
 };
 
 struct anv_image {
@@ -1190,6 +1276,7 @@ struct anv_image {
    VkExtent3D extent;
    uint32_t levels;
    uint32_t array_size;
+   VkImageUsageFlags usage; /**< Superset of VkImageCreateInfo::usage. */
 
    VkDeviceSize size;
    uint32_t alignment;
@@ -1198,8 +1285,10 @@ struct anv_image {
    struct anv_bo *bo;
    VkDeviceSize offset;
 
-   /** RENDER_SURFACE_STATE.SurfaceType */
-   uint8_t surf_type;
+   uint8_t surface_type; /**< RENDER_SURFACE_STATE.SurfaceType */
+
+   bool needs_nonrt_surface_state:1;
+   bool needs_color_rt_surface_state:1;
 
    /**
     * Image subsurfaces
@@ -1223,48 +1312,24 @@ struct anv_image {
    };
 };
 
-struct anv_surface_view {
-   struct anv_state surface_state; /**< RENDER_SURFACE_STATE */
-   struct anv_bo *bo;
-   uint32_t offset; /**< VkBufferCreateInfo::offset */
-   uint32_t range; /**< VkBufferCreateInfo::range */
-   const struct anv_format *format; /**< VkBufferCreateInfo::format */
-};
-
-struct anv_buffer_view {
-   struct anv_surface_view view;
-};
-
 struct anv_image_view {
-   struct anv_surface_view view;
-   VkExtent3D extent;
-};
+   const struct anv_image *image; /**< VkImageViewCreateInfo::image */
+   const struct anv_format *format; /**< VkImageViewCreateInfo::format */
+   struct anv_bo *bo;
+   uint32_t offset; /**< Offset into bo. */
+   VkExtent3D extent; /**< Extent of VkImageViewCreateInfo::baseMipLevel. */
 
-enum anv_attachment_view_type {
-   ANV_ATTACHMENT_VIEW_TYPE_COLOR,
-   ANV_ATTACHMENT_VIEW_TYPE_DEPTH_STENCIL,
-};
+   /** RENDER_SURFACE_STATE when using image as a color render target. */
+   struct anv_state color_rt_surface_state;
 
-struct anv_attachment_view {
-   enum anv_attachment_view_type attachment_type;
-   VkExtent3D extent;
-};
-
-struct anv_color_attachment_view {
-   struct anv_attachment_view base;
-   struct anv_surface_view view;
-};
-
-struct anv_depth_stencil_view {
-   struct anv_attachment_view base;
-   const struct anv_image *image; /**< VkAttachmentViewCreateInfo::image */
-   const struct anv_format *format; /**< VkAttachmentViewCreateInfo::format */
+   /** RENDER_SURFACE_STATE when using image as a non render target. */
+   struct anv_state nonrt_surface_state;
 };
 
 struct anv_image_create_info {
    const VkImageCreateInfo *vk_info;
-   bool force_tile_mode;
-   uint8_t tile_mode;
+   bool force_tiling;
+   enum isl_tiling tiling;
    uint32_t stride;
 };
 
@@ -1276,9 +1341,6 @@ struct anv_surface *
 anv_image_get_surface_for_aspect_mask(struct anv_image *image,
                                       VkImageAspectFlags aspect_mask);
 
-struct anv_surface *
-anv_image_get_surface_for_color_attachment(struct anv_image *image);
-
 void anv_image_view_init(struct anv_image_view *view,
                          struct anv_device *device,
                          const VkImageViewCreateInfo* pCreateInfo,
@@ -1296,36 +1358,17 @@ gen8_image_view_init(struct anv_image_view *iview,
                      const VkImageViewCreateInfo* pCreateInfo,
                      struct anv_cmd_buffer *cmd_buffer);
 
-void anv_color_attachment_view_init(struct anv_color_attachment_view *view,
-                                    struct anv_device *device,
-                                    const VkAttachmentViewCreateInfo* pCreateInfo,
-                                    struct anv_cmd_buffer *cmd_buffer);
-
-void gen7_color_attachment_view_init(struct anv_color_attachment_view *aview,
-                                     struct anv_device *device,
-                                     const VkAttachmentViewCreateInfo* pCreateInfo,
-                                     struct anv_cmd_buffer *cmd_buffer);
-
-void gen8_color_attachment_view_init(struct anv_color_attachment_view *aview,
-                                     struct anv_device *device,
-                                     const VkAttachmentViewCreateInfo* pCreateInfo,
-                                     struct anv_cmd_buffer *cmd_buffer);
-
-VkResult anv_buffer_view_create(struct anv_device *device,
-                                const VkBufferViewCreateInfo *pCreateInfo,
-                                struct anv_buffer_view **view_out);
-
 void anv_fill_buffer_surface_state(struct anv_device *device, void *state,
                                    const struct anv_format *format,
-                                   uint32_t offset, uint32_t range);
+                                   uint32_t offset, uint32_t range,
+                                   uint32_t stride);
 
 void gen7_fill_buffer_surface_state(void *state, const struct anv_format *format,
-                                    uint32_t offset, uint32_t range);
+                                    uint32_t offset, uint32_t range,
+                                    uint32_t stride);
 void gen8_fill_buffer_surface_state(void *state, const struct anv_format *format,
-                                    uint32_t offset, uint32_t range);
-
-void anv_surface_view_fini(struct anv_device *device,
-                           struct anv_surface_view *view);
+                                    uint32_t offset, uint32_t range,
+                                    uint32_t stride);
 
 struct anv_sampler {
    uint32_t state[4];
@@ -1336,11 +1379,8 @@ struct anv_framebuffer {
    uint32_t                                     height;
    uint32_t                                     layers;
 
-   /* Viewport for clears */
-   VkDynamicViewportState                       vp_state;
-
    uint32_t                                     attachment_count;
-   const struct anv_attachment_view *           attachments[0];
+   const struct anv_image_view *           attachments[0];
 };
 
 struct anv_subpass {
@@ -1362,15 +1402,12 @@ struct anv_render_pass_attachment {
 struct anv_render_pass {
    uint32_t                                     attachment_count;
    uint32_t                                     subpass_count;
-
-   uint32_t                                     num_color_clear_attachments;
-   bool                                         has_depth_clear_attachment;
-   bool                                         has_stencil_clear_attachment;
-
    struct anv_render_pass_attachment *          attachments;
    struct anv_subpass                           subpasses[0];
 };
 
+extern struct anv_render_pass anv_meta_dummy_renderpass;
+
 struct anv_query_pool_slot {
    uint64_t begin;
    uint64_t end;
@@ -1388,6 +1425,10 @@ void anv_device_finish_meta(struct anv_device *device);
 
 void *anv_lookup_entrypoint(const char *name);
 
+void anv_dump_image_to_ppm(struct anv_device *device,
+                           struct anv_image *image, unsigned miplevel,
+                           unsigned array_layer, const char *filename);
+
 #define ANV_DEFINE_HANDLE_CASTS(__anv_type, __VkType)                      \
                                                                            \
    static inline struct __anv_type *                                       \
@@ -1426,16 +1467,10 @@ ANV_DEFINE_HANDLE_CASTS(anv_physical_device, VkPhysicalDevice)
 ANV_DEFINE_HANDLE_CASTS(anv_queue, VkQueue)
 
 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_cmd_pool, VkCmdPool)
-ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_attachment_view, VkAttachmentView)
 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_buffer, VkBuffer)
-ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_buffer_view, VkBufferView);
 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_descriptor_set, VkDescriptorSet)
 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_descriptor_set_layout, VkDescriptorSetLayout)
 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_device_memory, VkDeviceMemory)
-ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_dynamic_cb_state, VkDynamicColorBlendState)
-ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_dynamic_ds_state, VkDynamicDepthStencilState)
-ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_dynamic_rs_state, VkDynamicRasterState)
-ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_dynamic_vp_state, VkDynamicViewportState)
 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_fence, VkFence)
 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_framebuffer, VkFramebuffer)
 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_image, VkImage)