mesa/src/intel/vulkan/anv_util.c

117 lines
3.3 KiB
C
Raw Normal View History

2015-05-08 22:32:37 -07:00
/*
* Copyright © 2015 Intel Corporation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice (including the next
* paragraph) shall be included in all copies or substantial portions of the
* Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
* IN THE SOFTWARE.
*/
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <assert.h>
#include "anv_private.h"
#include "vk_enum_to_str.h"
2015-05-08 22:32:37 -07:00
/** Log an error message. */
void anv_printflike(1, 2)
anv_loge(const char *format, ...)
{
va_list va;
va_start(va, format);
anv_loge_v(format, va);
va_end(va);
}
/** \see anv_loge() */
void
anv_loge_v(const char *format, va_list va)
{
mesa: Promote Intel's simple logging façade for Android to util/ I'm bringing up freedreno Vulkan on an Android phone, and my pains are exactly what Chad said when working on Intel's vulkan for Android in aa716db0f64d ("intel: Add simple logging façade for Android (v2)"): On Android, stdio goes to /dev/null. On Android, remote gdb is even more painful than the usual remote gdb. On Android, nothing works like you expect and debugging is hell. I need logging. This patch introduces a small, simple logging API that can easily wrap Android's API. On non-Android platforms, this logger does nothing fancy. It follows the time-honored Unix tradition of spewing everything to stderr with minimal fuss. My goal here is not perfection. My goal is to make a minimal, clean API, that people hate merely a little instead of a lot, and that's good enough to let me bring up Android Vulkan. And it needs to be fast, which means it must be small. No one wants to their game to miss frames while aiming a flaming bow into the jaws of an angry robot t-rex, and thus become t-rex breakfast, because some fool had too much fun desiging a bloated, ideal logging API. Compared to trusty fprintf, _mesa_log[ewi]() is actually usable on Android. Compared to os_log_message(), this has different error levels and supports format arguments. The only code change in the move is wrapping flockfile/funlockfile in !DETECT_OS_WINDOWS, since mingw32 doesn't have it. Windows likely wants different logging code, anyway. Reviewed-by: Tapani Pälli <tapani.palli@intel.com> Reviewed-by: Kristian H. Kristensen <hoegsberg@google.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6806>
2020-09-21 12:53:14 -07:00
mesa_loge_v(format, va);
}
void
__anv_perf_warn(struct anv_device *device,
const struct vk_object_base *object,
const char *file, int line, const char *format, ...)
{
va_list ap;
char buffer[256];
char report[512];
va_start(ap, format);
vsnprintf(buffer, sizeof(buffer), format, ap);
va_end(ap);
snprintf(report, sizeof(report), "%s: %s", file, buffer);
vk_debug_report(&device->physical->instance->vk.debug_report,
VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
object, line, 0, "anv", report);
mesa: Promote Intel's simple logging façade for Android to util/ I'm bringing up freedreno Vulkan on an Android phone, and my pains are exactly what Chad said when working on Intel's vulkan for Android in aa716db0f64d ("intel: Add simple logging façade for Android (v2)"): On Android, stdio goes to /dev/null. On Android, remote gdb is even more painful than the usual remote gdb. On Android, nothing works like you expect and debugging is hell. I need logging. This patch introduces a small, simple logging API that can easily wrap Android's API. On non-Android platforms, this logger does nothing fancy. It follows the time-honored Unix tradition of spewing everything to stderr with minimal fuss. My goal here is not perfection. My goal is to make a minimal, clean API, that people hate merely a little instead of a lot, and that's good enough to let me bring up Android Vulkan. And it needs to be fast, which means it must be small. No one wants to their game to miss frames while aiming a flaming bow into the jaws of an angry robot t-rex, and thus become t-rex breakfast, because some fool had too much fun desiging a bloated, ideal logging API. Compared to trusty fprintf, _mesa_log[ewi]() is actually usable on Android. Compared to os_log_message(), this has different error levels and supports format arguments. The only code change in the move is wrapping flockfile/funlockfile in !DETECT_OS_WINDOWS, since mingw32 doesn't have it. Windows likely wants different logging code, anyway. Reviewed-by: Tapani Pälli <tapani.palli@intel.com> Reviewed-by: Kristian H. Kristensen <hoegsberg@google.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6806>
2020-09-21 12:53:14 -07:00
mesa_logw("%s:%d: PERF: %s", file, line, buffer);
}
VkResult
__vk_errorv(struct anv_instance *instance,
const struct vk_object_base *object, VkResult error,
const char *file, int line, const char *format, va_list ap)
{
char buffer[256];
char report[512];
const char *error_str = vk_Result_to_str(error);
if (format) {
vsnprintf(buffer, sizeof(buffer), format, ap);
snprintf(report, sizeof(report), "%s:%d: %s (%s)", file, line, buffer,
error_str);
} else {
snprintf(report, sizeof(report), "%s:%d: %s", file, line, error_str);
}
if (instance) {
vk_debug_report(&instance->vk.debug_report,
VK_DEBUG_REPORT_ERROR_BIT_EXT,
object, line, 0, "anv", report);
}
mesa: Promote Intel's simple logging façade for Android to util/ I'm bringing up freedreno Vulkan on an Android phone, and my pains are exactly what Chad said when working on Intel's vulkan for Android in aa716db0f64d ("intel: Add simple logging façade for Android (v2)"): On Android, stdio goes to /dev/null. On Android, remote gdb is even more painful than the usual remote gdb. On Android, nothing works like you expect and debugging is hell. I need logging. This patch introduces a small, simple logging API that can easily wrap Android's API. On non-Android platforms, this logger does nothing fancy. It follows the time-honored Unix tradition of spewing everything to stderr with minimal fuss. My goal here is not perfection. My goal is to make a minimal, clean API, that people hate merely a little instead of a lot, and that's good enough to let me bring up Android Vulkan. And it needs to be fast, which means it must be small. No one wants to their game to miss frames while aiming a flaming bow into the jaws of an angry robot t-rex, and thus become t-rex breakfast, because some fool had too much fun desiging a bloated, ideal logging API. Compared to trusty fprintf, _mesa_log[ewi]() is actually usable on Android. Compared to os_log_message(), this has different error levels and supports format arguments. The only code change in the move is wrapping flockfile/funlockfile in !DETECT_OS_WINDOWS, since mingw32 doesn't have it. Windows likely wants different logging code, anyway. Reviewed-by: Tapani Pälli <tapani.palli@intel.com> Reviewed-by: Kristian H. Kristensen <hoegsberg@google.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6806>
2020-09-21 12:53:14 -07:00
mesa_loge("%s", report);
return error;
}
VkResult
__vk_errorf(struct anv_instance *instance,
const struct vk_object_base *object, VkResult error,
const char *file, int line, const char *format, ...)
{
va_list ap;
va_start(ap, format);
__vk_errorv(instance, object, error, file, line, format, ap);
va_end(ap);
return error;
}