1 /*-------------------------------------------------------------------------
5 * Copyright (c) 2015 Google Inc.
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
21 * \brief Vulkan utilites.
22 *//*--------------------------------------------------------------------*/
25 #include "vkStrUtil.hpp"
29 DE_STATIC_ASSERT(sizeof(vk::VkImageType) == sizeof(deUint32));
30 DE_STATIC_ASSERT(sizeof(vk::VkResult) == sizeof(deUint32));
31 DE_STATIC_ASSERT(sizeof(vk::VkDevice) == sizeof(void*));
32 DE_STATIC_ASSERT(sizeof(vk::VkBuffer) == sizeof(deUint64));
37 static bool isOutOfMemoryError (VkResult result)
39 return result == VK_ERROR_OUT_OF_DEVICE_MEMORY ||
40 result == VK_ERROR_OUT_OF_HOST_MEMORY;
43 Error::Error (VkResult error, const char* message, const char* expr, const char* file, int line)
44 : tcu::TestError (message, expr, file, line)
49 Error::Error (VkResult error, const std::string& message)
50 : tcu::TestError (message)
55 Error::~Error (void) throw()
59 OutOfMemoryError::OutOfMemoryError (VkResult error, const char* message, const char* expr, const char* file, int line)
60 : tcu::ResourceError(message, expr, file, line)
63 DE_ASSERT(isOutOfMemoryError(error));
66 OutOfMemoryError::OutOfMemoryError (VkResult error, const std::string& message)
67 : tcu::ResourceError(message)
70 DE_ASSERT(isOutOfMemoryError(error));
73 OutOfMemoryError::~OutOfMemoryError (void) throw()
77 void checkResult (VkResult result, const char* msg, const char* file, int line)
79 if (result != VK_SUCCESS)
81 std::ostringstream msgStr;
83 msgStr << msg << ": ";
85 msgStr << getResultStr(result);
87 if (isOutOfMemoryError(result))
88 throw OutOfMemoryError(result, msgStr.str().c_str(), DE_NULL, file, line);
90 throw Error(result, msgStr.str().c_str(), DE_NULL, file, line);