Path: blob/21.2-virgl/src/amd/vulkan/radv_util.c
7137 views
/*1* Copyright © 2015 Intel Corporation2*3* Permission is hereby granted, free of charge, to any person obtaining a4* copy of this software and associated documentation files (the "Software"),5* to deal in the Software without restriction, including without limitation6* the rights to use, copy, modify, merge, publish, distribute, sublicense,7* and/or sell copies of the Software, and to permit persons to whom the8* Software is furnished to do so, subject to the following conditions:9*10* The above copyright notice and this permission notice (including the next11* paragraph) shall be included in all copies or substantial portions of the12* Software.13*14* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR15* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,16* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL17* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER18* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING19* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS20* IN THE SOFTWARE.21*/2223#include <assert.h>24#include <errno.h>25#include <stdarg.h>26#include <stdio.h>27#include <stdlib.h>28#include <string.h>2930#include "radv_debug.h"31#include "radv_private.h"32#include "vk_enum_to_str.h"3334#include "util/u_math.h"3536/** Log an error message. */37void radv_printflike(1, 2) radv_loge(const char *format, ...)38{39va_list va;4041va_start(va, format);42radv_loge_v(format, va);43va_end(va);44}4546/** \see radv_loge() */47void48radv_loge_v(const char *format, va_list va)49{50fprintf(stderr, "vk: error: ");51vfprintf(stderr, format, va);52fprintf(stderr, "\n");53}5455/** Log an error message. */56void radv_printflike(1, 2) radv_logi(const char *format, ...)57{58va_list va;5960va_start(va, format);61radv_logi_v(format, va);62va_end(va);63}6465/** \see radv_logi() */66void67radv_logi_v(const char *format, va_list va)68{69fprintf(stderr, "radv: info: ");70vfprintf(stderr, format, va);71fprintf(stderr, "\n");72}7374void radv_printflike(3, 4) __radv_finishme(const char *file, int line, const char *format, ...)75{76va_list ap;77char buffer[256];7879va_start(ap, format);80vsnprintf(buffer, sizeof(buffer), format, ap);81va_end(ap);8283fprintf(stderr, "%s:%d: FINISHME: %s\n", file, line, buffer);84}8586VkResult87__vk_errorv(struct radv_instance *instance, const void *object, VkDebugReportObjectTypeEXT type,88VkResult error, const char *file, int line, const char *format, va_list ap)89{90char buffer[256];91char report[512];9293const char *error_str = vk_Result_to_str(error);9495#ifndef DEBUG96if (instance && !(instance->debug_flags & RADV_DEBUG_ERRORS))97return error;98#endif99100if (format) {101vsnprintf(buffer, sizeof(buffer), format, ap);102103snprintf(report, sizeof(report), "%s:%d: %s (%s)", file, line, buffer, error_str);104} else {105snprintf(report, sizeof(report), "%s:%d: %s", file, line, error_str);106}107108if (instance) {109vk_debug_report(&instance->vk, VK_DEBUG_REPORT_ERROR_BIT_EXT, object, line, 0, "radv",110report);111}112113fprintf(stderr, "%s\n", report);114115return error;116}117118VkResult119__vk_errorf(struct radv_instance *instance, const void *object, VkDebugReportObjectTypeEXT type,120VkResult error, const char *file, int line, const char *format, ...)121{122va_list ap;123124va_start(ap, format);125__vk_errorv(instance, object, type, error, file, line, format, ap);126va_end(ap);127128return error;129}130131132