winsys/amdgpu: add back multithreaded command submission
[mesa.git] / src / gallium / winsys / amdgpu / drm / amdgpu_winsys.h
1 /*
2 * Copyright © 2009 Corbin Simpson
3 * Copyright © 2015 Advanced Micro Devices, Inc.
4 * All Rights Reserved.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining
7 * a copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sub license, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
16 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17 * NON-INFRINGEMENT. IN NO EVENT SHALL THE COPYRIGHT HOLDERS, AUTHORS
18 * AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
20 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
21 * USE OR OTHER DEALINGS IN THE SOFTWARE.
22 *
23 * The above copyright notice and this permission notice (including the
24 * next paragraph) shall be included in all copies or substantial portions
25 * of the Software.
26 */
27 /*
28 * Authors:
29 * Marek Olšák <maraeo@gmail.com>
30 */
31
32 #ifndef AMDGPU_WINSYS_H
33 #define AMDGPU_WINSYS_H
34
35 #include "pipebuffer/pb_cache.h"
36 #include "gallium/drivers/radeon/radeon_winsys.h"
37 #include "addrlib/addrinterface.h"
38 #include "os/os_thread.h"
39 #include <amdgpu.h>
40
41 struct amdgpu_cs;
42
43 struct amdgpu_winsys {
44 struct radeon_winsys base;
45 struct pipe_reference reference;
46 struct pb_cache bo_cache;
47
48 amdgpu_device_handle dev;
49
50 pipe_mutex bo_fence_lock;
51
52 int num_cs; /* The number of command streams created. */
53 uint32_t next_bo_unique_id;
54 uint64_t allocated_vram;
55 uint64_t allocated_gtt;
56 uint64_t buffer_wait_time; /* time spent in buffer_wait in ns */
57 uint64_t num_cs_flushes;
58
59 struct radeon_info info;
60
61 /* multithreaded IB submission */
62 pipe_mutex cs_queue_lock;
63 pipe_semaphore cs_queue_has_space;
64 pipe_semaphore cs_queued;
65 pipe_thread thread;
66 int kill_thread;
67 int num_enqueued_cs;
68 struct amdgpu_cs *cs_queue[8];
69
70 struct amdgpu_gpu_info amdinfo;
71 ADDR_HANDLE addrlib;
72 uint32_t rev_id;
73 unsigned family;
74
75 /* List of all allocated buffers */
76 pipe_mutex global_bo_list_lock;
77 struct list_head global_bo_list;
78 unsigned num_buffers;
79 };
80
81 static inline struct amdgpu_winsys *
82 amdgpu_winsys(struct radeon_winsys *base)
83 {
84 return (struct amdgpu_winsys*)base;
85 }
86
87 void amdgpu_ws_queue_cs(struct amdgpu_winsys *ws, struct amdgpu_cs *cs);
88 void amdgpu_surface_init_functions(struct amdgpu_winsys *ws);
89 ADDR_HANDLE amdgpu_addr_create(struct amdgpu_winsys *ws);
90
91 #endif