turnip: disable tiling as necessary
[mesa.git] / src / freedreno / vulkan / tu_private.h
index 416731a45a43503e4f4c0dc20c25717196a5a23f..feb460db566043c9a36b7b9731284c94bdde539c 100644 (file)
 #endif
 
 #include "c11/threads.h"
-#include "compiler/shader_enums.h"
 #include "main/macros.h"
 #include "util/list.h"
 #include "util/macros.h"
 #include "vk_alloc.h"
 #include "vk_debug_report.h"
+#include "wsi_common.h"
 
-#include "drm/msm_drm.h"
+#include "drm-uapi/msm_drm.h"
 #include "ir3/ir3_compiler.h"
 #include "ir3/ir3_shader.h"
 
@@ -102,6 +102,9 @@ typedef uint32_t xcb_window_t;
  */
 #define TU_BUFFER_OPS_CS_THRESHOLD 4096
 
+#define A6XX_TEX_CONST_DWORDS 16
+#define A6XX_TEX_SAMP_DWORDS 4
+
 enum tu_mem_heap
 {
    TU_MEM_HEAP_VRAM,
@@ -210,6 +213,8 @@ tu_clear_mask(uint32_t *inout_mask, uint32_t clear_mask)
       memcpy((dest), (src), (count) * sizeof(*(src)));                       \
    })
 
+#define COND(bool, val) ((bool) ? (val) : 0)
+
 /* Whenever we generate an error, pass it through this function. Useful for
  * debugging, where we can break on it. Only call at error site, not when
  * propagating errors. Might be useful to plug in a stack trace here.
@@ -298,6 +303,8 @@ struct tu_physical_device
    uint8_t device_uuid[VK_UUID_SIZE];
    uint8_t cache_uuid[VK_UUID_SIZE];
 
+   struct wsi_device wsi_device;
+
    int local_fd;
    int master_fd;
 
@@ -338,6 +345,11 @@ struct tu_instance
    struct tu_instance_extension_table enabled_extensions;
 };
 
+VkResult
+tu_wsi_init(struct tu_physical_device *physical_device);
+void
+tu_wsi_finish(struct tu_physical_device *physical_device);
+
 bool
 tu_instance_extension_supported(const char *name);
 uint32_t
@@ -573,6 +585,8 @@ struct tu_descriptor_set
    uint64_t va;
    uint32_t *mapped_ptr;
    struct tu_descriptor_range *dynamic_descriptors;
+
+   struct tu_bo *descriptors[0];
 };
 
 struct tu_push_descriptor_set
@@ -590,7 +604,7 @@ struct tu_descriptor_pool_entry
 
 struct tu_descriptor_pool
 {
-   uint8_t *mapped_ptr;
+   struct tu_bo bo;
    uint64_t current_offset;
    uint64_t size;
 
@@ -799,11 +813,30 @@ struct tu_tiling_config
    uint32_t pipe_sizes[MAX_VSC_PIPES];
 };
 
+enum tu_cmd_dirty_bits
+{
+   TU_CMD_DIRTY_PIPELINE = 1 << 0,
+   TU_CMD_DIRTY_VERTEX_BUFFERS = 1 << 1,
+   TU_CMD_DIRTY_DESCRIPTOR_SETS = 1 << 2,
+
+   TU_CMD_DIRTY_DYNAMIC_LINE_WIDTH = 1 << 16,
+   TU_CMD_DIRTY_DYNAMIC_STENCIL_COMPARE_MASK = 1 << 17,
+   TU_CMD_DIRTY_DYNAMIC_STENCIL_WRITE_MASK = 1 << 18,
+   TU_CMD_DIRTY_DYNAMIC_STENCIL_REFERENCE = 1 << 19,
+};
+
 struct tu_cmd_state
 {
-   /* Vertex descriptors */
-   uint64_t vb_va;
-   unsigned vb_size;
+   uint32_t dirty;
+
+   struct tu_pipeline *pipeline;
+
+   /* Vertex buffers */
+   struct
+   {
+      struct tu_buffer *buffers[MAX_VBS];
+      VkDeviceSize offsets[MAX_VBS];
+   } vb;
 
    struct tu_dynamic_state dynamic;
 
@@ -901,6 +934,8 @@ struct tu_cmd_buffer
 
    struct tu_bo_list bo_list;
    struct tu_cs cs;
+   struct tu_cs draw_cs;
+   struct tu_cs draw_state;
    struct tu_cs tile_cs;
 
    uint16_t marker_reg;
@@ -923,6 +958,14 @@ tu_get_memory_fd(struct tu_device *device,
                  struct tu_device_memory *memory,
                  int *pFD);
 
+static inline struct tu_descriptor_state *
+tu_get_descriptors_state(struct tu_cmd_buffer *cmd_buffer,
+                         VkPipelineBindPoint bind_point)
+{
+   assert(bind_point == VK_PIPELINE_BIND_POINT_GRAPHICS);
+   return &cmd_buffer->descriptors[bind_point];
+}
+
 /*
  * Takes x,y,z as exact numbers of invocations, instead of blocks.
  *
@@ -938,7 +981,7 @@ tu_unaligned_dispatch(struct tu_cmd_buffer *cmd_buffer,
 
 struct tu_event
 {
-   uint64_t *map;
+   struct tu_bo bo;
 };
 
 struct tu_shader_module;
@@ -989,10 +1032,21 @@ struct tu_shader_compile_options
    bool include_binning_pass;
 };
 
+struct tu_descriptor_map
+{
+   unsigned num;
+   int set[32];
+   int binding[32];
+};
+
 struct tu_shader
 {
    struct ir3_shader ir3_shader;
 
+   struct tu_descriptor_map texture_map;
+   struct tu_descriptor_map sampler_map;
+   struct tu_descriptor_map ubo_map;
+
    /* This may be true for vertex shaders.  When true, variants[1] is the
     * binning variant and binning_binary is non-NULL.
     */
@@ -1027,6 +1081,20 @@ tu_shader_compile(struct tu_device *dev,
                   const struct tu_shader_compile_options *options,
                   const VkAllocationCallbacks *alloc);
 
+struct tu_program_descriptor_linkage
+{
+   struct ir3_ubo_analysis_state ubo_state;
+
+   uint32_t constlen;
+
+   uint32_t offset_ubo; /* ubo pointers const offset */
+   uint32_t num_ubo; /* number of ubo pointers */
+
+   struct tu_descriptor_map texture_map;
+   struct tu_descriptor_map sampler_map;
+   struct tu_descriptor_map ubo_map;
+};
+
 struct tu_pipeline
 {
    struct tu_cs cs;
@@ -1043,6 +1111,8 @@ struct tu_pipeline
       struct tu_bo binary_bo;
       struct tu_cs_entry state_ib;
       struct tu_cs_entry binning_state_ib;
+
+      struct tu_program_descriptor_linkage link[MESA_SHADER_STAGES];
    } program;
 
    struct
@@ -1180,6 +1250,8 @@ struct tu_image
    VkExtent3D extent;
    uint32_t level_count;
    uint32_t layer_count;
+   VkSampleCountFlagBits samples;
+
 
    VkDeviceSize size;
    uint32_t alignment;
@@ -1188,6 +1260,7 @@ struct tu_image
    VkDeviceSize layer_size;
    struct tu_image_level levels[15];
    unsigned tile_mode;
+   unsigned cpp;
 
    unsigned queue_family_mask;
    bool exclusive;
@@ -1197,7 +1270,7 @@ struct tu_image
    VkDeviceMemory owned_memory;
 
    /* Set when bound */
-   const struct tu_bo *bo;
+   struct tu_bo *bo;
    VkDeviceSize bo_offset;
 };
 
@@ -1237,16 +1310,19 @@ struct tu_image_view
    uint32_t level_count;
    VkExtent3D extent; /**< Extent of VkImageViewCreateInfo::baseMipLevel. */
 
-   uint32_t descriptor[16];
+   uint32_t descriptor[A6XX_TEX_CONST_DWORDS];
 
    /* Descriptor for use as a storage image as opposed to a sampled image.
     * This has a few differences for cube maps (e.g. type).
     */
-   uint32_t storage_descriptor[16];
+   uint32_t storage_descriptor[A6XX_TEX_CONST_DWORDS];
 };
 
 struct tu_sampler
 {
+   uint32_t state[A6XX_TEX_SAMP_DWORDS];
+
+   bool needs_border;
 };
 
 struct tu_image_create_info
@@ -1429,7 +1505,7 @@ tu_update_descriptor_set_with_template(
    struct tu_device *device,
    struct tu_cmd_buffer *cmd_buffer,
    struct tu_descriptor_set *set,
-   VkDescriptorUpdateTemplateKHR descriptorUpdateTemplate,
+   VkDescriptorUpdateTemplate descriptorUpdateTemplate,
    const void *pData);
 
 void
@@ -1510,7 +1586,7 @@ TU_DEFINE_NONDISP_HANDLE_CASTS(tu_descriptor_set, VkDescriptorSet)
 TU_DEFINE_NONDISP_HANDLE_CASTS(tu_descriptor_set_layout,
                                VkDescriptorSetLayout)
 TU_DEFINE_NONDISP_HANDLE_CASTS(tu_descriptor_update_template,
-                               VkDescriptorUpdateTemplateKHR)
+                               VkDescriptorUpdateTemplate)
 TU_DEFINE_NONDISP_HANDLE_CASTS(tu_device_memory, VkDeviceMemory)
 TU_DEFINE_NONDISP_HANDLE_CASTS(tu_fence, VkFence)
 TU_DEFINE_NONDISP_HANDLE_CASTS(tu_event, VkEvent)