xref: /aosp_15_r20/external/mesa3d/src/intel/vulkan/anv_util.c (revision 6104692788411f58d303aa86923a9ff6ecaded22)
1 /*
2  * Copyright © 2015 Intel Corporation
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a
5  * copy of this software and associated documentation files (the "Software"),
6  * to deal in the Software without restriction, including without limitation
7  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8  * and/or sell copies of the Software, and to permit persons to whom the
9  * Software is furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice (including the next
12  * paragraph) shall be included in all copies or substantial portions of the
13  * Software.
14  *
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
18  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21  * IN THE SOFTWARE.
22  */
23 
24 #include <stdarg.h>
25 #include <stdio.h>
26 #include <stdlib.h>
27 #include <string.h>
28 #include <errno.h>
29 #include <assert.h>
30 
31 #include "anv_private.h"
32 #include "vk_enum_to_str.h"
33 
34 void
__anv_perf_warn(struct anv_device * device,const struct vk_object_base * object,const char * file,int line,const char * format,...)35 __anv_perf_warn(struct anv_device *device,
36                 const struct vk_object_base *object,
37                 const char *file, int line, const char *format, ...)
38 {
39    va_list ap;
40    char buffer[256];
41 
42    va_start(ap, format);
43    vsnprintf(buffer, sizeof(buffer), format, ap);
44    va_end(ap);
45 
46    if (object) {
47       __vk_log(VK_DEBUG_UTILS_MESSAGE_SEVERITY_WARNING_BIT_EXT,
48                VK_DEBUG_UTILS_MESSAGE_TYPE_PERFORMANCE_BIT_EXT,
49                VK_LOG_OBJS(object), file, line,
50                "PERF: %s", buffer);
51    } else {
52       __vk_log(VK_DEBUG_UTILS_MESSAGE_SEVERITY_WARNING_BIT_EXT,
53                VK_DEBUG_UTILS_MESSAGE_TYPE_PERFORMANCE_BIT_EXT,
54                VK_LOG_NO_OBJS(device->physical->instance), file, line,
55                "PERF: %s", buffer);
56    }
57 }
58 
59 void
anv_dump_pipe_bits(enum anv_pipe_bits bits,FILE * f)60 anv_dump_pipe_bits(enum anv_pipe_bits bits, FILE *f)
61 {
62    if (bits & ANV_PIPE_DEPTH_CACHE_FLUSH_BIT)
63       fputs("+depth_flush ", f);
64    if (bits & ANV_PIPE_DATA_CACHE_FLUSH_BIT)
65       fputs("+dc_flush ", f);
66    if (bits & ANV_PIPE_HDC_PIPELINE_FLUSH_BIT)
67       fputs("+hdc_flush ", f);
68    if (bits & ANV_PIPE_RENDER_TARGET_CACHE_FLUSH_BIT)
69       fputs("+rt_flush ", f);
70    if (bits & ANV_PIPE_TILE_CACHE_FLUSH_BIT)
71       fputs("+tile_flush ", f);
72    if (bits & ANV_PIPE_STATE_CACHE_INVALIDATE_BIT)
73       fputs("+state_inval ", f);
74    if (bits & ANV_PIPE_CONSTANT_CACHE_INVALIDATE_BIT)
75       fputs("+const_inval ", f);
76    if (bits & ANV_PIPE_VF_CACHE_INVALIDATE_BIT)
77       fputs("+vf_inval ", f);
78    if (bits & ANV_PIPE_TEXTURE_CACHE_INVALIDATE_BIT)
79       fputs("+tex_inval ", f);
80    if (bits & ANV_PIPE_INSTRUCTION_CACHE_INVALIDATE_BIT)
81       fputs("+ic_inval ", f);
82    if (bits & ANV_PIPE_STALL_AT_SCOREBOARD_BIT)
83       fputs("+pb_stall ", f);
84    if (bits & ANV_PIPE_PSS_STALL_SYNC_BIT)
85       fputs("+pss_stall ", f);
86    if (bits & ANV_PIPE_DEPTH_STALL_BIT)
87       fputs("+depth_stall ", f);
88    if (bits & ANV_PIPE_CS_STALL_BIT ||
89        bits & ANV_PIPE_END_OF_PIPE_SYNC_BIT)
90       fputs("+cs_stall ", f);
91    if (bits & ANV_PIPE_UNTYPED_DATAPORT_CACHE_FLUSH_BIT)
92       fputs("+utdp_flush ", f);
93    if (bits & ANV_PIPE_CCS_CACHE_FLUSH_BIT)
94       fputs("+ccs_flush ", f);
95 }
96 
97 const char *
anv_gfx_state_bit_to_str(enum anv_gfx_state_bits state)98 anv_gfx_state_bit_to_str(enum anv_gfx_state_bits state)
99 {
100 #define NAME(name) case ANV_GFX_STATE_##name: return #name;
101    switch (state) {
102       NAME(URB);
103       NAME(VF_STATISTICS);
104       NAME(VF_SGVS);
105       NAME(VF_SGVS_2);
106       NAME(VF_SGVS_INSTANCING);
107       NAME(PRIMITIVE_REPLICATION);
108       NAME(MULTISAMPLE);
109       NAME(SBE);
110       NAME(SBE_SWIZ);
111       NAME(SO_DECL_LIST);
112       NAME(VS);
113       NAME(HS);
114       NAME(DS);
115       NAME(GS);
116       NAME(PS);
117       NAME(PS_EXTRA);
118       NAME(SBE_MESH);
119       NAME(CLIP_MESH);
120       NAME(MESH_CONTROL);
121       NAME(MESH_SHADER);
122       NAME(MESH_DISTRIB);
123       NAME(TASK_CONTROL);
124       NAME(TASK_SHADER);
125       NAME(TASK_REDISTRIB);
126       NAME(BLEND_STATE_PTR);
127       NAME(CLIP);
128       NAME(CC_STATE);
129       NAME(CC_STATE_PTR);
130       NAME(CPS);
131       NAME(DEPTH_BOUNDS);
132       NAME(INDEX_BUFFER);
133       NAME(LINE_STIPPLE);
134       NAME(PS_BLEND);
135       NAME(RASTER);
136       NAME(SAMPLE_MASK);
137       NAME(SAMPLE_PATTERN);
138       NAME(SCISSOR);
139       NAME(SF);
140       NAME(STREAMOUT);
141       NAME(TE);
142       NAME(VERTEX_INPUT);
143       NAME(VF);
144       NAME(VF_TOPOLOGY);
145       NAME(VFG);
146       NAME(VIEWPORT_CC);
147       NAME(VIEWPORT_CC_PTR);
148       NAME(VIEWPORT_SF_CLIP);
149       NAME(WM);
150       NAME(WM_DEPTH_STENCIL);
151       NAME(PMA_FIX);
152       NAME(WA_18019816803);
153       NAME(TBIMR_TILE_PASS_INFO);
154    default: unreachable("invalid state");
155    }
156 }
157 
158 VkResult
anv_device_print_init(struct anv_device * device)159 anv_device_print_init(struct anv_device *device)
160 {
161    VkResult result =
162       anv_device_alloc_bo(device, "printf",
163                           debug_get_num_option("ANV_PRINTF_BUFFER_SIZE", 1024 * 1024),
164                           ANV_BO_ALLOC_CAPTURE |
165                           ANV_BO_ALLOC_MAPPED |
166                           ANV_BO_ALLOC_HOST_COHERENT |
167                           ANV_BO_ALLOC_NO_LOCAL_MEM,
168                           0 /* explicit_address */,
169                           &device->printf.bo);
170    if (result != VK_SUCCESS)
171       return result;
172 
173    util_dynarray_init(&device->printf.prints, ralloc_context(NULL));
174    simple_mtx_init(&device->printf.mutex, mtx_plain);
175 
176    *((uint32_t *)device->printf.bo->map) = 4;
177 
178    return VK_SUCCESS;
179 }
180 
181 void
anv_device_print_fini(struct anv_device * device)182 anv_device_print_fini(struct anv_device *device)
183 {
184    anv_device_release_bo(device, device->printf.bo);
185    util_dynarray_fini(&device->printf.prints);
186    simple_mtx_destroy(&device->printf.mutex);
187 }
188 
189 void
anv_device_print_shader_prints(struct anv_device * device)190 anv_device_print_shader_prints(struct anv_device *device)
191 {
192    simple_mtx_lock(&device->printf.mutex);
193 
194    uint32_t *size = device->printf.bo->map;
195 
196    u_printf_ptr(stdout,
197                 device->printf.bo->map + sizeof(uint32_t),
198                 *size - 4,
199                 util_dynarray_begin(&device->printf.prints),
200                 util_dynarray_num_elements(&device->printf.prints, u_printf_info*));
201 
202    /* Reset */
203    *size = 4;
204 
205    simple_mtx_unlock(&device->printf.mutex);
206 }
207