• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*-------------------------------------------------------------------------
2  * Vulkan CTS Framework
3  * --------------------
4  *
5  * Copyright (c) 2015 Google Inc.
6  *
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
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
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.
18  *
19  *//*!
20  * \file
21  * \brief Vulkan utilites.
22  *//*--------------------------------------------------------------------*/
23 
24 #include "vkDefs.hpp"
25 #include "vkStrUtil.hpp"
26 
27 #include <sstream>
28 
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));
33 
34 namespace vk
35 {
36 
isOutOfMemoryError(VkResult result)37 static bool isOutOfMemoryError (VkResult result)
38 {
39 	return result == VK_ERROR_OUT_OF_DEVICE_MEMORY	||
40 		   result == VK_ERROR_OUT_OF_HOST_MEMORY;
41 }
42 
Error(VkResult error,const char * message,const char * expr,const char * file,int line)43 Error::Error (VkResult error, const char* message, const char* expr, const char* file, int line)
44 	: tcu::TestError	(message, expr, file, line)
45 	, m_error			(error)
46 {
47 }
48 
Error(VkResult error,const std::string & message)49 Error::Error (VkResult error, const std::string& message)
50 	: tcu::TestError	(message)
51 	, m_error			(error)
52 {
53 }
54 
~Error(void)55 Error::~Error (void) throw()
56 {
57 }
58 
NotSupportedError(VkResult error,const char * message,const char * expr,const char * file,int line)59 NotSupportedError::NotSupportedError (VkResult error, const char* message, const char* expr, const char* file, int line)
60 	: tcu::NotSupportedError	(message, expr, file, line)
61 	, m_error					(error)
62 {
63 }
64 
NotSupportedError(VkResult error,const std::string & message)65 NotSupportedError::NotSupportedError (VkResult error, const std::string& message)
66 	: tcu::NotSupportedError	(message)
67 	, m_error					(error)
68 {
69 }
70 
~NotSupportedError(void)71 NotSupportedError::~NotSupportedError (void) throw()
72 {
73 }
74 
OutOfMemoryError(VkResult error,const char * message,const char * expr,const char * file,int line)75 OutOfMemoryError::OutOfMemoryError (VkResult error, const char* message, const char* expr, const char* file, int line)
76 	: tcu::ResourceError(message, expr, file, line)
77 	, m_error			(error)
78 {
79 	DE_ASSERT(isOutOfMemoryError(error));
80 }
81 
OutOfMemoryError(VkResult error,const std::string & message)82 OutOfMemoryError::OutOfMemoryError (VkResult error, const std::string& message)
83 	: tcu::ResourceError(message)
84 	, m_error			(error)
85 {
86 	DE_ASSERT(isOutOfMemoryError(error));
87 }
88 
~OutOfMemoryError(void)89 OutOfMemoryError::~OutOfMemoryError (void) throw()
90 {
91 }
92 
93 template<typename ERROR>
checkResult(VkResult result,const char * msg,const char * file,int line)94 static void checkResult (VkResult result, const char* msg, const char* file, int line)
95 {
96 	if (result != VK_SUCCESS)
97 	{
98 		std::ostringstream msgStr;
99 		if (msg)
100 			msgStr << msg << ": ";
101 
102 		msgStr << getResultStr(result);
103 
104 		if (isOutOfMemoryError(result))
105 			throw OutOfMemoryError(result, msgStr.str().c_str(), DE_NULL, file, line);
106 		else
107 			throw ERROR(result, msgStr.str().c_str(), DE_NULL, file, line);
108 	}
109 }
110 
checkResult(VkResult result,const char * msg,const char * file,int line)111 void checkResult (VkResult result, const char* msg, const char* file, int line)
112 {
113 	checkResult<Error>(result, msg, file, line);
114 }
115 
checkResultSupported(VkResult result,const char * msg,const char * file,int line)116 void checkResultSupported (VkResult result, const char* msg, const char* file, int line)
117 {
118 	checkResult<NotSupportedError>(result, msg, file, line);
119 }
120 
checkWsiResult(VkResult result,const char * msg,const char * file,int line)121 void checkWsiResult (VkResult result, const char* msg, const char* file, int line)
122 {
123 	if (result == VK_SUBOPTIMAL_KHR)
124 		return;
125 #ifndef CTS_USES_VULKANSC
126 	if (result == VK_ERROR_FULL_SCREEN_EXCLUSIVE_MODE_LOST_EXT)
127 		return;
128 #endif // CTS_USES_VULKANSC
129 
130 	checkResult(result, msg, file, line);
131 }
132 
133 } // vk
134