27
27
#include <string.h>
28
28
#include "sun_java2d_vulkan_VKGPU.h"
29
29
#include "VKUtil.h"
30
+ #include "VKCapabilityUtil.h"
30
31
#include "VKEnv.h"
31
32
#include "VKAllocator.h"
32
33
#include "VKRenderer.h"
@@ -71,7 +72,6 @@ static VkBool32 VKDevice_CheckAndAddFormat(VKEnv* vk, VkPhysicalDevice physicalD
71
72
}
72
73
73
74
void VKDevice_CheckAndAdd (VKEnv * vk , VkPhysicalDevice physicalDevice ) {
74
- jint caps = 0 ;
75
75
// Query device properties.
76
76
VkPhysicalDeviceVulkan12Features device12Features = {
77
77
.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_2_FEATURES ,
@@ -85,27 +85,55 @@ void VKDevice_CheckAndAdd(VKEnv* vk, VkPhysicalDevice physicalDevice) {
85
85
VkPhysicalDeviceProperties2 deviceProperties2 = {.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROPERTIES_2 };
86
86
vk -> vkGetPhysicalDeviceProperties2 (physicalDevice , & deviceProperties2 );
87
87
88
- // Check features.
89
- J2dRlsTrace5 (J2D_TRACE_INFO , "\t- %s (%d.%d.%d, %s) " ,
88
+ // Query supported layers.
89
+ uint32_t layerCount ;
90
+ VK_IF_ERROR (vk -> vkEnumerateDeviceLayerProperties (physicalDevice , & layerCount , NULL )) return ;
91
+ VkLayerProperties allLayers [layerCount ];
92
+ VK_IF_ERROR (vk -> vkEnumerateDeviceLayerProperties (physicalDevice , & layerCount , allLayers )) return ;
93
+
94
+ // Query supported extensions.
95
+ uint32_t extensionCount ;
96
+ VK_IF_ERROR (vk -> vkEnumerateDeviceExtensionProperties (physicalDevice , NULL , & extensionCount , NULL )) return ;
97
+ VkExtensionProperties allExtensions [extensionCount ];
98
+ VK_IF_ERROR (vk -> vkEnumerateDeviceExtensionProperties (physicalDevice , NULL , & extensionCount , allExtensions )) return ;
99
+
100
+ // Check API version.
101
+ ARRAY (pchar ) errors = NULL ;
102
+ jint caps = 0 ;
103
+ J2dRlsTraceLn5 (J2D_TRACE_INFO , "%s (%d.%d.%d, %s)" ,
90
104
(const char * ) deviceProperties2 .properties .deviceName ,
91
105
VK_API_VERSION_MAJOR (deviceProperties2 .properties .apiVersion ),
92
106
VK_API_VERSION_MINOR (deviceProperties2 .properties .apiVersion ),
93
107
VK_API_VERSION_PATCH (deviceProperties2 .properties .apiVersion ),
94
108
physicalDeviceTypeString (deviceProperties2 .properties .deviceType ))
95
109
if (deviceProperties2 .properties .apiVersion < REQUIRED_VULKAN_VERSION ) {
96
- J2dRlsTraceLn (J2D_TRACE_INFO , " - unsupported API version, skipped" )
97
- return ;
110
+ ARRAY_PUSH_BACK (errors ) = "Unsupported API version" ;
98
111
}
99
112
100
- if (!deviceFeatures2 .features .logicOp ) {
101
- J2dRlsTraceLn (J2D_TRACE_INFO , " - hasLogicOp not supported, skipped" )
102
- return ;
103
- }
104
- if (!device12Features .timelineSemaphore ) {
105
- J2dRlsTraceLn (J2D_TRACE_INFO , " - hasTimelineSemaphore not supported, skipped" )
106
- return ;
107
- }
108
- J2dRlsTraceLn (J2D_TRACE_INFO , "" )
113
+ // Log layers and extensions.
114
+ VKNamedEntry_LogAll ("device layers" , allLayers [0 ].layerName , layerCount , sizeof (VkLayerProperties ));
115
+ VKNamedEntry_LogAll ("device extensions" , allExtensions [0 ].extensionName , extensionCount , sizeof (VkExtensionProperties ));
116
+
117
+ // Check layers.
118
+ VKNamedEntry * layers = NULL ;
119
+ #ifdef DEBUG
120
+ DEF_NAMED_ENTRY (layers , VK_KHR_VALIDATION_LAYER );
121
+ #endif
122
+ VKNamedEntry_Match (layers , allLayers [0 ].layerName , layerCount , sizeof (VkLayerProperties ));
123
+ VKNamedEntry_LogFound (layers );
124
+
125
+ // Check extensions.
126
+ VKNamedEntry * extensions = NULL ;
127
+ DEF_NAMED_ENTRY (extensions , VK_KHR_SWAPCHAIN_EXTENSION );
128
+ VKNamedEntry_Match (extensions , allExtensions [0 ].extensionName , extensionCount , sizeof (VkExtensionProperties ));
129
+ VKNamedEntry_LogFound (extensions );
130
+
131
+ // Check features.
132
+ J2dRlsTraceLn1 (J2D_TRACE_INFO , " logicOp = %s" , deviceFeatures2 .features .logicOp ? "true" : "false" )
133
+ if (deviceFeatures2 .features .logicOp ) caps |= sun_java2d_vulkan_VKGPU_CAP_LOGIC_OP_BIT ;
134
+
135
+ J2dRlsTraceLn1 (J2D_TRACE_INFO , " timelineSemaphore = %s" , device12Features .timelineSemaphore ? "true" : "false" )
136
+ if (!device12Features .timelineSemaphore ) ARRAY_PUSH_BACK (errors ) = "timelineSemaphore not supported" ;
109
137
110
138
// Query queue family properties.
111
139
uint32_t queueFamilyCount = 0 ;
@@ -119,7 +147,8 @@ void VKDevice_CheckAndAdd(VKEnv* vk, VkPhysicalDevice physicalDevice) {
119
147
int64_t queueFamily = -1 ;
120
148
for (uint32_t j = 0 ; j < queueFamilyCount ; j ++ ) {
121
149
VkBool32 presentationSupported = VK_FALSE ;
122
- if (vk -> platformData != NULL && vk -> platformData -> checkPresentationSupport != NULL ) {
150
+ if (vk -> presentationSupported && VK_KHR_SWAPCHAIN_EXTENSION .found &&
151
+ vk -> platformData != NULL && vk -> platformData -> checkPresentationSupport != NULL ) {
123
152
presentationSupported = vk -> platformData -> checkPresentationSupport (vk , physicalDevice , j );
124
153
}
125
154
char logFlags [5 ] = {
@@ -144,22 +173,7 @@ void VKDevice_CheckAndAdd(VKEnv* vk, VkPhysicalDevice physicalDevice) {
144
173
}
145
174
}
146
175
}
147
- if (queueFamily == -1 ) {
148
- J2dRlsTraceLn (J2D_TRACE_INFO , " --------------------- Suitable queue not found, skipped" )
149
- return ;
150
- }
151
-
152
- // Query supported layers.
153
- uint32_t layerCount ;
154
- VK_IF_ERROR (vk -> vkEnumerateDeviceLayerProperties (physicalDevice , & layerCount , NULL )) return ;
155
- VkLayerProperties layers [layerCount ];
156
- VK_IF_ERROR (vk -> vkEnumerateDeviceLayerProperties (physicalDevice , & layerCount , layers )) return ;
157
-
158
- // Query supported extensions.
159
- uint32_t extensionCount ;
160
- VK_IF_ERROR (vk -> vkEnumerateDeviceExtensionProperties (physicalDevice , NULL , & extensionCount , NULL )) return ;
161
- VkExtensionProperties extensions [extensionCount ];
162
- VK_IF_ERROR (vk -> vkEnumerateDeviceExtensionProperties (physicalDevice , NULL , & extensionCount , extensions )) return ;
176
+ if (queueFamily == -1 ) ARRAY_PUSH_BACK (errors ) = "Suitable queue not found" ;
163
177
164
178
// Query supported formats.
165
179
J2dRlsTraceLn (J2D_TRACE_INFO , " Supported device formats:" )
@@ -208,11 +222,8 @@ void VKDevice_CheckAndAdd(VKEnv* vk, VkPhysicalDevice physicalDevice) {
208
222
209
223
// Check sampled formats capabilities.
210
224
if (SRCTYPE_4BYTE -> format == VK_FORMAT_UNDEFINED ) {
211
- J2dRlsTraceLn (J2D_TRACE_INFO , " - 4-byte sampled format not found, skipped" )
212
- ARRAY_FREE (supportedFormats );
213
- return ;
214
- }
215
- caps |= sun_java2d_vulkan_VKGPU_CAP_SAMPLED_4BYTE_BIT ;
225
+ ARRAY_PUSH_BACK (errors ) = "4-byte sampled format not found" ;
226
+ } else caps |= sun_java2d_vulkan_VKGPU_CAP_SAMPLED_4BYTE_BIT ;
216
227
if (SRCTYPE_3BYTE -> format != VK_FORMAT_UNDEFINED ) caps |= sun_java2d_vulkan_VKGPU_CAP_SAMPLED_3BYTE_BIT ;
217
228
if (SRCTYPE_565 -> format != VK_FORMAT_UNDEFINED ) caps |= sun_java2d_vulkan_VKGPU_CAP_SAMPLED_565_BIT ;
218
229
if (SRCTYPE_555 -> format != VK_FORMAT_UNDEFINED ) caps |= sun_java2d_vulkan_VKGPU_CAP_SAMPLED_555_BIT ;
@@ -222,61 +233,21 @@ void VKDevice_CheckAndAdd(VKEnv* vk, VkPhysicalDevice physicalDevice) {
222
233
vk -> vkGetPhysicalDeviceFormatProperties (physicalDevice , VK_FORMAT_S8_UINT , & formatProperties );
223
234
if ((formatProperties .optimalTilingFeatures & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT ) != 0 ) {
224
235
J2dRlsTraceLn1 (J2D_TRACE_INFO , " %s" , "VK_FORMAT_S8_UINT (stencil)" )
225
- } else {
226
- J2dRlsTraceLn (J2D_TRACE_INFO , " - VK_FORMAT_S8_UINT not supported, skipped" )
227
- ARRAY_FREE (supportedFormats );
228
- return ;
229
- }
236
+ } else ARRAY_PUSH_BACK (errors ) = "VK_FORMAT_S8_UINT not supported" ;
230
237
}
231
238
232
- // Log layers.
233
- J2dRlsTraceLn (J2D_TRACE_VERBOSE , " Supported device layers:" )
234
- for (uint32_t j = 0 ; j < layerCount ; j ++ ) {
235
- J2dRlsTraceLn1 (J2D_TRACE_VERBOSE , " %s" , (char * ) layers [j ].layerName )
236
- }
237
-
238
- // Check extensions.
239
- J2dRlsTraceLn (J2D_TRACE_VERBOSE , " Supported device extensions:" )
240
- VkBool32 hasSwapChain = VK_FALSE ;
241
- for (uint32_t j = 0 ; j < extensionCount ; j ++ ) {
242
- J2dRlsTraceLn1 (J2D_TRACE_VERBOSE , " %s" , (char * ) extensions [j ].extensionName )
243
- hasSwapChain = hasSwapChain || strcmp (VK_KHR_SWAPCHAIN_EXTENSION_NAME , extensions [j ].extensionName ) == 0 ;
244
- }
245
- J2dRlsTraceLn (J2D_TRACE_VERBOSE , "Vulkan: Found device extensions:" )
246
- J2dRlsTraceLn1 (J2D_TRACE_VERBOSE , " " VK_KHR_SWAPCHAIN_EXTENSION_NAME " = %s" , hasSwapChain ? "true" : "false" )
247
-
248
- if (!hasSwapChain ) {
249
- J2dRlsTraceLn (J2D_TRACE_INFO ,
250
- " --------------------- Required " VK_KHR_SWAPCHAIN_EXTENSION_NAME " not found, skipped" )
251
- ARRAY_FREE (supportedFormats );
239
+ // Check found errors.
240
+ if (errors != NULL ) {
241
+ J2dRlsTraceLn (J2D_TRACE_WARNING , " Device is not supported:" )
242
+ VKCapabilityUtil_LogErrors (J2D_TRACE_WARNING , errors );
243
+ ARRAY_FREE (errors );
252
244
return ;
253
245
}
254
246
255
- ARRAY (pchar ) deviceEnabledLayers = NULL ;
256
- ARRAY (pchar ) deviceEnabledExtensions = NULL ;
257
- ARRAY_PUSH_BACK (deviceEnabledExtensions ) = VK_KHR_SWAPCHAIN_EXTENSION_NAME ;
258
-
259
- // Check validation layer.
260
- #ifdef DEBUG
261
- int validationLayerNotSupported = 1 ;
262
- for (uint32_t j = 0 ; j < layerCount ; j ++ ) {
263
- if (strcmp ("VK_LAYER_KHRONOS_validation" , layers [j ].layerName ) == 0 ) {
264
- validationLayerNotSupported = 0 ;
265
- ARRAY_PUSH_BACK (deviceEnabledLayers ) = "VK_LAYER_KHRONOS_validation" ;
266
- break ;
267
- }
268
- }
269
- if (validationLayerNotSupported ) {
270
- J2dRlsTraceLn1 (J2D_TRACE_INFO , " %s device layer is not supported" , "VK_LAYER_KHRONOS_validation" )
271
- }
272
- #endif
273
-
274
247
// Copy device name.
275
248
char * deviceName = strdup (deviceProperties2 .properties .deviceName );
276
249
if (deviceName == NULL ) {
277
- J2dRlsTraceLn (J2D_TRACE_ERROR , "Vulkan: Cannot duplicate deviceName" )
278
- ARRAY_FREE (deviceEnabledLayers );
279
- ARRAY_FREE (deviceEnabledExtensions );
250
+ J2dRlsTraceLn (J2D_TRACE_ERROR , " Cannot duplicate deviceName" )
280
251
ARRAY_FREE (supportedFormats );
281
252
return ;
282
253
}
@@ -288,8 +259,8 @@ void VKDevice_CheckAndAdd(VKEnv* vk, VkPhysicalDevice physicalDevice) {
288
259
.handle = VK_NULL_HANDLE ,
289
260
.physicalDevice = physicalDevice ,
290
261
.queueFamily = queueFamily ,
291
- .enabledLayers = deviceEnabledLayers ,
292
- .enabledExtensions = deviceEnabledExtensions ,
262
+ .enabledLayers = VKNamedEntry_CollectNames ( layers ) ,
263
+ .enabledExtensions = VKNamedEntry_CollectNames ( extensions ) ,
293
264
.sampledSrcTypes = sampledSrcTypes ,
294
265
.supportedFormats = supportedFormats ,
295
266
.caps = caps
0 commit comments