1b8e80941Smrg/* 2b8e80941Smrg * Copyright © 2015 Intel Corporation 3b8e80941Smrg * 4b8e80941Smrg * Permission is hereby granted, free of charge, to any person obtaining a 5b8e80941Smrg * copy of this software and associated documentation files (the "Software"), 6b8e80941Smrg * to deal in the Software without restriction, including without limitation 7b8e80941Smrg * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8b8e80941Smrg * and/or sell copies of the Software, and to permit persons to whom the 9b8e80941Smrg * Software is furnished to do so, subject to the following conditions: 10b8e80941Smrg * 11b8e80941Smrg * The above copyright notice and this permission notice (including the next 12b8e80941Smrg * paragraph) shall be included in all copies or substantial portions of the 13b8e80941Smrg * Software. 14b8e80941Smrg * 15b8e80941Smrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16b8e80941Smrg * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17b8e80941Smrg * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 18b8e80941Smrg * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19b8e80941Smrg * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 20b8e80941Smrg * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 21b8e80941Smrg * IN THE SOFTWARE. 22b8e80941Smrg */ 23b8e80941Smrg 24b8e80941Smrg#include <stdarg.h> 25b8e80941Smrg#include <stdio.h> 26b8e80941Smrg#include <stdlib.h> 27b8e80941Smrg#include <string.h> 28b8e80941Smrg#include <errno.h> 29b8e80941Smrg#include <assert.h> 30b8e80941Smrg 31b8e80941Smrg#include "anv_private.h" 32b8e80941Smrg#include "vk_enum_to_str.h" 33b8e80941Smrg 34b8e80941Smrg/** Log an error message. */ 35b8e80941Smrgvoid anv_printflike(1, 2) 36b8e80941Smrganv_loge(const char *format, ...) 37b8e80941Smrg{ 38b8e80941Smrg va_list va; 39b8e80941Smrg 40b8e80941Smrg va_start(va, format); 41b8e80941Smrg anv_loge_v(format, va); 42b8e80941Smrg va_end(va); 43b8e80941Smrg} 44b8e80941Smrg 45b8e80941Smrg/** \see anv_loge() */ 46b8e80941Smrgvoid 47b8e80941Smrganv_loge_v(const char *format, va_list va) 48b8e80941Smrg{ 49b8e80941Smrg intel_loge_v(format, va); 50b8e80941Smrg} 51b8e80941Smrg 52b8e80941Smrgvoid anv_printflike(6, 7) 53b8e80941Smrg__anv_perf_warn(struct anv_instance *instance, const void *object, 54b8e80941Smrg VkDebugReportObjectTypeEXT type, 55b8e80941Smrg const char *file, int line, const char *format, ...) 56b8e80941Smrg{ 57b8e80941Smrg va_list ap; 58b8e80941Smrg char buffer[256]; 59b8e80941Smrg char report[512]; 60b8e80941Smrg 61b8e80941Smrg va_start(ap, format); 62b8e80941Smrg vsnprintf(buffer, sizeof(buffer), format, ap); 63b8e80941Smrg va_end(ap); 64b8e80941Smrg 65b8e80941Smrg snprintf(report, sizeof(report), "%s: %s", file, buffer); 66b8e80941Smrg 67b8e80941Smrg vk_debug_report(&instance->debug_report_callbacks, 68b8e80941Smrg VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, 69b8e80941Smrg type, 70b8e80941Smrg (uint64_t) (uintptr_t) object, 71b8e80941Smrg line, 72b8e80941Smrg 0, 73b8e80941Smrg "anv", 74b8e80941Smrg report); 75b8e80941Smrg 76b8e80941Smrg intel_logw("%s:%d: PERF: %s", file, line, buffer); 77b8e80941Smrg} 78b8e80941Smrg 79b8e80941SmrgVkResult 80b8e80941Smrg__vk_errorv(struct anv_instance *instance, const void *object, 81b8e80941Smrg VkDebugReportObjectTypeEXT type, VkResult error, 82b8e80941Smrg const char *file, int line, const char *format, va_list ap) 83b8e80941Smrg{ 84b8e80941Smrg char buffer[256]; 85b8e80941Smrg char report[512]; 86b8e80941Smrg 87b8e80941Smrg const char *error_str = vk_Result_to_str(error); 88b8e80941Smrg 89b8e80941Smrg if (format) { 90b8e80941Smrg vsnprintf(buffer, sizeof(buffer), format, ap); 91b8e80941Smrg 92b8e80941Smrg snprintf(report, sizeof(report), "%s:%d: %s (%s)", file, line, buffer, 93b8e80941Smrg error_str); 94b8e80941Smrg } else { 95b8e80941Smrg snprintf(report, sizeof(report), "%s:%d: %s", file, line, error_str); 96b8e80941Smrg } 97b8e80941Smrg 98b8e80941Smrg if (instance) { 99b8e80941Smrg vk_debug_report(&instance->debug_report_callbacks, 100b8e80941Smrg VK_DEBUG_REPORT_ERROR_BIT_EXT, 101b8e80941Smrg type, 102b8e80941Smrg (uint64_t) (uintptr_t) object, 103b8e80941Smrg line, 104b8e80941Smrg 0, 105b8e80941Smrg "anv", 106b8e80941Smrg report); 107b8e80941Smrg } 108b8e80941Smrg 109b8e80941Smrg intel_loge("%s", report); 110b8e80941Smrg 111b8e80941Smrg return error; 112b8e80941Smrg} 113b8e80941Smrg 114b8e80941SmrgVkResult 115b8e80941Smrg__vk_errorf(struct anv_instance *instance, const void *object, 116b8e80941Smrg VkDebugReportObjectTypeEXT type, VkResult error, 117b8e80941Smrg const char *file, int line, const char *format, ...) 118b8e80941Smrg{ 119b8e80941Smrg va_list ap; 120b8e80941Smrg 121b8e80941Smrg va_start(ap, format); 122b8e80941Smrg __vk_errorv(instance, object, type, error, file, line, format, ap); 123b8e80941Smrg va_end(ap); 124b8e80941Smrg 125b8e80941Smrg return error; 126b8e80941Smrg} 127