vk: Add an initial implementation of the actual Khronos WSI extension
[mesa.git] / src / vulkan / anv_private.h
index f0d4233b046e2beadc325f51ff057a203b4a5dd1..06ef4e123f35399d2a260745bd4b8f4672b0008e 100644 (file)
@@ -46,7 +46,8 @@
 #define VK_PROTOTYPES
 #include <vulkan/vulkan.h>
 #include <vulkan/vulkan_intel.h>
-#include <vulkan/vk_wsi_lunarg.h>
+#include <vulkan/vk_wsi_swapchain.h>
+#include <vulkan/vk_wsi_device_swapchain.h>
 
 #include "anv_entrypoints.h"
 
@@ -120,16 +121,15 @@ struct anv_common {
  * propagating errors. Might be useful to plug in a stack trace here.
  */
 
-static inline VkResult
-vk_error(VkResult error)
-{
+VkResult __vk_errorf(VkResult error, const char *file, int line, const char *format, ...);
+
 #ifdef DEBUG
-   fprintf(stderr, "vk_error: %x\n", error);
+#define vk_error(error) __vk_errorf(error, __FILE__, __LINE__, NULL);
+#define vk_errorf(error, format, ...) __vk_errorf(error, __FILE__, __LINE__, format, ## __VA_ARGS__);
+#else
+#define vk_error(error) error
 #endif
 
-   return error;
-}
-
 void __anv_finishme(const char *file, int line, const char *format, ...)
    anv_printflike(3, 4);
 void anv_loge(const char *format, ...) anv_printflike(1, 2);
@@ -505,7 +505,7 @@ __gen_combine_address(struct anv_batch *batch, void *location,
                       const struct anv_address address, uint32_t delta)
 {
    if (address.bo == NULL) {
-      return delta;
+      return address.offset + delta;
    } else {
       assert(batch->start <= location && location < batch->end);
 
@@ -642,6 +642,7 @@ anv_descriptor_set_destroy(struct anv_device *device,
 #define MAX_VBS   32
 #define MAX_SETS   8
 #define MAX_RTS    8
+#define MAX_PUSH_CONSTANTS_SIZE 128
 
 struct anv_pipeline_layout {
    struct {
@@ -684,6 +685,16 @@ struct anv_descriptor_set_binding {
    uint32_t                                     dynamic_offsets[128];
 };
 
+struct anv_push_constant_data {
+    uint8_t client_data[MAX_PUSH_CONSTANTS_SIZE];
+    uint8_t driver_data[0];
+};
+
+struct anv_push_constants {
+    uint32_t driver_data_size;
+    struct anv_push_constant_data *data;
+};
+
 /** State required while building cmd buffer */
 struct anv_cmd_state {
    uint32_t                                     current_pipeline;
@@ -691,6 +702,7 @@ struct anv_cmd_state {
    uint32_t                                     dirty;
    uint32_t                                     compute_dirty;
    uint32_t                                     descriptors_dirty;
+   uint32_t                                     push_constants_dirty;
    uint32_t                                     scratch_size;
    struct anv_pipeline *                        pipeline;
    struct anv_pipeline *                        compute_pipeline;
@@ -704,6 +716,7 @@ struct anv_cmd_state {
    uint32_t                                     state_vf[GEN8_3DSTATE_VF_length];
    struct anv_vertex_binding                    vertex_bindings[MAX_VBS];
    struct anv_descriptor_set_binding            descriptors[MAX_SETS];
+   struct anv_push_constants                    push_constants[VK_SHADER_STAGE_NUM];
 
    struct {
       struct anv_buffer *                       index_buffer;
@@ -828,9 +841,15 @@ void gen8_cmd_buffer_begin_subpass(struct anv_cmd_buffer *cmd_buffer,
 void anv_cmd_buffer_begin_subpass(struct anv_cmd_buffer *cmd_buffer,
                                   struct anv_subpass *subpass);
 
+struct anv_state
+anv_cmd_buffer_push_constants(struct anv_cmd_buffer *cmd_buffer,
+                              VkShaderStage stage);
+
 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 *
+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);
 
@@ -1041,16 +1060,29 @@ struct anv_image {
    struct anv_bo *bo;
    VkDeviceSize offset;
 
-   struct anv_swap_chain *swap_chain;
-
    /** RENDER_SURFACE_STATE.SurfaceType */
    uint8_t surf_type;
 
-   /** Primary surface is either color or depth. */
-   struct anv_surface primary_surface;
+   /**
+    * Image subsurfaces
+    *
+    * For each foo, anv_image::foo_surface is valid if and only if
+    * anv_image::format has a foo aspect.
+    *
+    * The hardware requires that the depth buffer and stencil buffer be
+    * separate surfaces.  From Vulkan's perspective, though, depth and stencil
+    * reside in the same VkImage.  To satisfy both the hardware and Vulkan, we
+    * allocate the depth and stencil buffers as separate surfaces in the same
+    * bo.
+    */
+   union {
+      struct anv_surface color_surface;
 
-   /** Stencil surface is optional. */
-   struct anv_surface stencil_surface;
+      struct {
+         struct anv_surface depth_surface;
+         struct anv_surface stencil_surface;
+      };
+   };
 };
 
 struct anv_surface_view {
@@ -1087,17 +1119,8 @@ struct anv_color_attachment_view {
 
 struct anv_depth_stencil_view {
    struct anv_attachment_view base;
-
-   struct anv_bo *bo;
-
-   uint32_t depth_offset; /**< Offset into bo. */
-   uint32_t depth_stride; /**< 3DSTATE_DEPTH_BUFFER.SurfacePitch */
-   uint32_t depth_format; /**< 3DSTATE_DEPTH_BUFFER.SurfaceFormat */
-   uint16_t depth_qpitch; /**< 3DSTATE_DEPTH_BUFFER.SurfaceQPitch */
-
-   uint32_t stencil_offset; /**< Offset into bo. */
-   uint32_t stencil_stride; /**< 3DSTATE_STENCIL_BUFFER.SurfacePitch */
-   uint16_t stencil_qpitch; /**< 3DSTATE_STENCIL_BUFFER.SurfaceQPitch */
+   const struct anv_image *image; /**< VkAttachmentViewCreateInfo::image */
+   const struct anv_format *format; /**< VkAttachmentViewCreateInfo::format */
 };
 
 struct anv_image_create_info {
@@ -1111,6 +1134,12 @@ VkResult anv_image_create(VkDevice _device,
                           const struct anv_image_create_info *info,
                           VkImage *pImage);
 
+struct anv_surface *
+anv_image_get_surface_for_aspect(struct anv_image *image, VkImageAspect aspect);
+
+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,
@@ -1256,7 +1285,6 @@ ANV_DEFINE_HANDLE_CASTS(anv_device, VkDevice)
 ANV_DEFINE_HANDLE_CASTS(anv_instance, VkInstance)
 ANV_DEFINE_HANDLE_CASTS(anv_physical_device, VkPhysicalDevice)
 ANV_DEFINE_HANDLE_CASTS(anv_queue, VkQueue)
-ANV_DEFINE_HANDLE_CASTS(anv_swap_chain, VkSwapChainWSI);
 
 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_cmd_pool, VkCmdPool)
 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_attachment_view, VkAttachmentView)