radv: add semaphore support
[mesa.git] / src / amd / vulkan / radv_private.h
index 6db8c7acfe38a12677f992038d42e4c2513daa1a..e6f6c29c919be911f5094a4588272e18b61496a0 100644 (file)
@@ -47,7 +47,9 @@
 #include "compiler/shader_enums.h"
 #include "util/macros.h"
 #include "util/list.h"
+#include "util/vk_alloc.h"
 #include "main/macros.h"
+
 #include "radv_radeon_winsys.h"
 #include "ac_binary.h"
 #include "ac_nir_to_llvm.h"
@@ -68,6 +70,7 @@ typedef uint32_t xcb_window_t;
 
 #include "radv_entrypoints.h"
 
+#include "wsi_common.h"
 
 #define MAX_VBS         32
 #define MAX_VERTEX_ATTRIBS 32
@@ -82,12 +85,24 @@ typedef uint32_t xcb_window_t;
 
 #define NUM_DEPTH_CLEAR_PIPELINES 3
 
+enum radv_mem_heap {
+       RADV_MEM_HEAP_VRAM,
+       RADV_MEM_HEAP_VRAM_CPU_ACCESS,
+       RADV_MEM_HEAP_GTT,
+       RADV_MEM_HEAP_COUNT
+};
+
+enum radv_mem_type {
+       RADV_MEM_TYPE_VRAM,
+       RADV_MEM_TYPE_GTT_WRITE_COMBINE,
+       RADV_MEM_TYPE_VRAM_CPU_ACCESS,
+       RADV_MEM_TYPE_GTT_CACHED,
+       RADV_MEM_TYPE_COUNT
+};
+
 #define radv_noreturn __attribute__((__noreturn__))
 #define radv_printflike(a, b) __attribute__((__format__(__printf__, a, b)))
 
-#define MIN(a, b) ((a) < (b) ? (a) : (b))
-#define MAX(a, b) ((a) > (b) ? (a) : (b))
-
 static inline uint32_t
 align_u32(uint32_t v, uint32_t a)
 {
@@ -141,7 +156,7 @@ radv_minify(uint32_t n, uint32_t levels)
        if (unlikely(n == 0))
                return 0;
        else
-               return MAX(n >> levels, 1);
+               return MAX2(n >> levels, 1);
 }
 static inline float
 radv_clamp_f(float f, float min, float max)
@@ -173,20 +188,12 @@ radv_clear_mask(uint32_t *inout_mask, uint32_t clear_mask)
             __dword &= ~(1 << (b)))
 
 #define typed_memcpy(dest, src, count) ({                              \
-                       static_assert(sizeof(*src) == sizeof(*dest), ""); \
+                       STATIC_ASSERT(sizeof(*src) == sizeof(*dest)); \
                        memcpy((dest), (src), (count) * sizeof(*(src))); \
                })
 
 #define zero(x) (memset(&(x), 0, sizeof(x)))
 
-/* Define no kernel as 1, since that's an illegal offset for a kernel */
-#define NO_KERNEL 1
-
-struct radv_common {
-       VkStructureType                             sType;
-       const void*                                 pNext;
-};
-
 /* 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.
@@ -211,7 +218,13 @@ void radv_loge_v(const char *format, va_list va);
  * Print a FINISHME message, including its source location.
  */
 #define radv_finishme(format, ...)                                     \
-       __radv_finishme(__FILE__, __LINE__, format, ##__VA_ARGS__);
+       do { \
+               static bool reported = false; \
+               if (!reported) { \
+                       __radv_finishme(__FILE__, __LINE__, format, ##__VA_ARGS__); \
+                       reported = true; \
+               } \
+       } while (0)
 
 /* A non-fatal assert.  Useful for debugging. */
 #ifdef DEBUG
@@ -238,113 +251,11 @@ void radv_abortfv(const char *format, va_list va) radv_noreturn;
                return;                                 \
        } while (0)
 
-/**
- * A dynamically growable, circular buffer.  Elements are added at head and
- * removed from tail. head and tail are free-running uint32_t indices and we
- * only compute the modulo with size when accessing the array.  This way,
- * number of bytes in the queue is always head - tail, even in case of
- * wraparound.
- */
-
-struct radv_vector {
-   uint32_t head;
-   uint32_t tail;
-   uint32_t element_size;
-   uint32_t size;
-   void *data;
-};
-
-int radv_vector_init(struct radv_vector *queue, uint32_t element_size, uint32_t size);
-void *radv_vector_add(struct radv_vector *queue);
-void *radv_vector_remove(struct radv_vector *queue);
-
-static inline int
-radv_vector_length(struct radv_vector *queue)
-{
-   return (queue->head - queue->tail) / queue->element_size;
-}
-
-static inline void *
-radv_vector_head(struct radv_vector *vector)
-{
-   assert(vector->tail < vector->head);
-   return (void *)((char *)vector->data +
-                   ((vector->head - vector->element_size) &
-                    (vector->size - 1)));
-}
-
-static inline void *
-radv_vector_tail(struct radv_vector *vector)
-{
-   return (void *)((char *)vector->data + (vector->tail & (vector->size - 1)));
-}
-
-static inline void
-radv_vector_finish(struct radv_vector *queue)
-{
-   free(queue->data);
-}
-
-#define radv_vector_foreach(elem, queue)                                  \
-   static_assert(__builtin_types_compatible_p(__typeof__(queue), struct radv_vector *), ""); \
-   for (uint32_t __radv_vector_offset = (queue)->tail;                                \
-        elem = (queue)->data + (__radv_vector_offset & ((queue)->size - 1)), __radv_vector_offset < (queue)->head; \
-        __radv_vector_offset += (queue)->element_size)
-
 void *radv_resolve_entrypoint(uint32_t index);
 void *radv_lookup_entrypoint(const char *name);
 
 extern struct radv_dispatch_table dtable;
 
-static inline void *
-radv_alloc(const VkAllocationCallbacks *alloc,
-          size_t size, size_t align,
-          VkSystemAllocationScope scope)
-{
-       return alloc->pfnAllocation(alloc->pUserData, size, align, scope);
-}
-
-static inline void *
-radv_realloc(const VkAllocationCallbacks *alloc,
-            void *ptr, size_t size, size_t align,
-            VkSystemAllocationScope scope)
-{
-       return alloc->pfnReallocation(alloc->pUserData, ptr, size, align, scope);
-}
-
-static inline void
-radv_free(const VkAllocationCallbacks *alloc, void *data)
-{
-       alloc->pfnFree(alloc->pUserData, data);
-}
-
-static inline void *
-radv_alloc2(const VkAllocationCallbacks *parent_alloc,
-           const VkAllocationCallbacks *alloc,
-           size_t size, size_t align,
-           VkSystemAllocationScope scope)
-{
-       if (alloc)
-               return radv_alloc(alloc, size, align, scope);
-       else
-               return radv_alloc(parent_alloc, size, align, scope);
-}
-
-static inline void
-radv_free2(const VkAllocationCallbacks *parent_alloc,
-          const VkAllocationCallbacks *alloc,
-          void *data)
-{
-       if (alloc)
-               radv_free(alloc, data);
-       else
-               radv_free(parent_alloc, data);
-}
-
-struct radv_wsi_interaface;
-
-#define VK_ICD_WSI_PLATFORM_MAX 5
-
 struct radv_physical_device {
        VK_LOADER_DATA                              _loader_data;
 
@@ -360,7 +271,9 @@ struct radv_physical_device {
        uint32_t                    pci_vendor_id;
        uint32_t                    pci_device_id;
 
-       struct radv_wsi_interface *                  wsi[VK_ICD_WSI_PLATFORM_MAX];
+       uint8_t                                     uuid[VK_UUID_SIZE];
+
+       struct wsi_device                       wsi_device;
 };
 
 struct radv_instance {
@@ -484,6 +397,16 @@ struct radv_meta_state {
                VkDescriptorSetLayout                     img_ds_layout;
                VkPipeline pipeline;
        } btoi;
+       struct {
+               VkPipelineLayout                          img_p_layout;
+               VkDescriptorSetLayout                     img_ds_layout;
+               VkPipeline pipeline;
+       } itoi;
+       struct {
+               VkPipelineLayout                          img_p_layout;
+               VkDescriptorSetLayout                     img_ds_layout;
+               VkPipeline pipeline;
+       } cleari;
 
        struct {
                VkPipeline                                pipeline;
@@ -521,12 +444,20 @@ struct radv_meta_state {
        } buffer;
 };
 
+/* queue types */
+#define RADV_QUEUE_GENERAL 0
+#define RADV_QUEUE_COMPUTE 1
+#define RADV_QUEUE_TRANSFER 2
+
+#define RADV_MAX_QUEUE_FAMILIES 3
+
+enum ring_type radv_queue_family_to_ring(int f);
+
 struct radv_queue {
        VK_LOADER_DATA                              _loader_data;
-
        struct radv_device *                         device;
-
-       struct radv_state_pool *                     pool;
+       int queue_family_index;
+       int queue_idx;
 };
 
 struct radv_device {
@@ -539,11 +470,14 @@ struct radv_device {
        struct radeon_winsys_ctx *hw_ctx;
 
        struct radv_meta_state                       meta_state;
-       struct radv_queue                            queue;
+
+       struct radv_queue *queues[RADV_MAX_QUEUE_FAMILIES];
+       int queue_count[RADV_MAX_QUEUE_FAMILIES];
        struct radeon_winsys_cs *empty_cs;
 
        bool allow_fast_clears;
        bool allow_dcc;
+       bool shader_stats_dump;
 
        /* MSAA sample locations.
         * The first index is the sample index.
@@ -555,8 +489,6 @@ struct radv_device {
        float sample_locations_16x[16][2];
 };
 
-void radv_device_get_cache_uuid(void *uuid);
-
 struct radv_device_memory {
        struct radeon_winsys_bo                      *bo;
        uint32_t                                     type_index;
@@ -744,10 +676,13 @@ struct radv_cmd_state {
        enum radv_cmd_flush_bits                     flush_bits;
        unsigned                                     active_occlusion_queries;
        float                                        offset_scale;
+       uint32_t                                      descriptors_dirty;
 };
+
 struct radv_cmd_pool {
        VkAllocationCallbacks                        alloc;
        struct list_head                             cmd_buffers;
+       uint32_t queue_family_index;
 };
 
 struct radv_cmd_buffer_upload {
@@ -770,6 +705,7 @@ struct radv_cmd_buffer {
        VkCommandBufferLevel                         level;
        struct radeon_winsys_cs *cs;
        struct radv_cmd_state state;
+       uint32_t queue_family_index;
 
        uint8_t push_constants[MAX_PUSH_CONSTANTS_SIZE];
        uint32_t dynamic_buffers[16 * MAX_DYNAMIC_BUFFERS];
@@ -782,6 +718,10 @@ struct radv_cmd_buffer {
 
 struct radv_image;
 
+bool radv_cmd_buffer_uses_mec(struct radv_cmd_buffer *cmd_buffer);
+
+void si_init_compute(struct radv_physical_device *physical_device,
+                    struct radv_cmd_buffer *cmd_buffer);
 void si_init_config(struct radv_physical_device *physical_device,
                    struct radv_cmd_buffer *cmd_buffer);
 void si_write_viewport(struct radeon_winsys_cs *cs, int first_vp,
@@ -896,6 +836,7 @@ struct radv_shader_variant {
        struct ac_shader_variant_info info;
        unsigned rsrc1;
        unsigned rsrc2;
+       uint32_t code_size;
 };
 
 struct radv_depth_stencil_state {
@@ -1035,10 +976,6 @@ struct radv_cmask_info {
        uint64_t offset;
        uint64_t size;
        unsigned alignment;
-       unsigned pitch;
-       unsigned height;
-       unsigned xalign;
-       unsigned yalign;
        unsigned slice_tile_max;
        unsigned base_address_reg;
 };
@@ -1308,6 +1245,13 @@ void radv_initialise_cmask(struct radv_cmd_buffer *cmd_buffer,
                           struct radv_image *image, uint32_t value);
 void radv_initialize_dcc(struct radv_cmd_buffer *cmd_buffer,
                         struct radv_image *image, uint32_t value);
+
+struct radv_fence {
+       struct radeon_winsys_fence *fence;
+       bool submitted;
+       bool signalled;
+};
+
 #define RADV_DEFINE_HANDLE_CASTS(__radv_type, __VkType)                \
                                                                \
        static inline struct __radv_type *                      \
@@ -1373,12 +1317,4 @@ RADV_DEFINE_NONDISP_HANDLE_CASTS(radv_shader_module, VkShaderModule)
                return (const __VkType *) __radv_obj;                   \
        }
 
-#define RADV_COMMON_TO_STRUCT(__VkType, __vk_name, __common_name)      \
-       const __VkType *__vk_name = radv_common_to_ ## __VkType(__common_name)
-
-RADV_DEFINE_STRUCT_CASTS(radv_common, VkMemoryBarrier)
-RADV_DEFINE_STRUCT_CASTS(radv_common, VkBufferMemoryBarrier)
-RADV_DEFINE_STRUCT_CASTS(radv_common, VkImageMemoryBarrier)
-
-
 #endif /* RADV_PRIVATE_H */