Skip to content

Commit 69ea0a0

Browse files
committed
JBR-8608 Vulkan: Cleanup capability checks
1 parent f211a48 commit 69ea0a0

File tree

9 files changed

+256
-195
lines changed

9 files changed

+256
-195
lines changed

src/java.desktop/share/classes/sun/java2d/vulkan/VKBlitLoops.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -546,7 +546,7 @@ private static int encode3Byte(int r, int g, int b) {
546546
}
547547

548548
private static boolean hasCap(VKSurfaceData dst, int cap) {
549-
return (dst.getGraphicsConfig().getGPU().getCaps() & cap) != 0;
549+
return dst.getGraphicsConfig().getGPU().hasCap(cap);
550550
}
551551

552552
/**

src/java.desktop/share/classes/sun/java2d/vulkan/VKEnv.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ public static synchronized void init(long nativePtr) {
8080
Options.deviceNumber : 0];
8181
// Check whether the presentation is supported.
8282
for (VKGPU device : devices) {
83-
if ((device.getCaps() & VKGPU.CAP_PRESENTABLE_BIT) != 0 &&
83+
if (device.hasCap(VKGPU.CAP_PRESENTABLE_BIT) &&
8484
device.getPresentableGraphicsConfigs().findAny().isPresent()) {
8585
newState |= PRESENT_BIT;
8686
break;

src/java.desktop/share/classes/sun/java2d/vulkan/VKGPU.java

+5
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
public class VKGPU {
4040

4141
@Native public static final int CAP_PRESENTABLE_BIT = 0x80000000;
42+
@Native public static final int CAP_LOGIC_OP_BIT = 0x40000000;
4243
@Native public static final int CAP_SAMPLED_4BYTE_BIT = 0; // Considered always supported.
4344
@Native public static final int CAP_SAMPLED_3BYTE_BIT = 1;
4445
@Native public static final int CAP_SAMPLED_565_BIT = 2;
@@ -98,6 +99,10 @@ public int getCaps() {
9899
return caps;
99100
}
100101

102+
public boolean hasCap(int cap) {
103+
return (caps & cap) == cap;
104+
}
105+
101106
/**
102107
* Initialize the device and return its native handle.
103108
*/
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
/*
2+
* Copyright (c) 2023, Oracle and/or its affiliates. All rights reserved.
3+
* Copyright (c) 2023, JetBrains s.r.o.. All rights reserved.
4+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5+
*
6+
* This code is free software; you can redistribute it and/or modify it
7+
* under the terms of the GNU General Public License version 2 only, as
8+
* published by the Free Software Foundation. Oracle designates this
9+
* particular file as subject to the "Classpath" exception as provided
10+
* by Oracle in the LICENSE file that accompanied this code.
11+
*
12+
* This code is distributed in the hope that it will be useful, but WITHOUT
13+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15+
* version 2 for more details (a copy is included in the LICENSE file that
16+
* accompanied this code).
17+
*
18+
* You should have received a copy of the GNU General Public License version
19+
* 2 along with this work; if not, write to the Free Software Foundation,
20+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
21+
*
22+
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
23+
* or visit www.oracle.com if you need additional information or have any
24+
* questions.
25+
*/
26+
27+
#ifndef VKCapabilityUtil_h_Included
28+
#define VKCapabilityUtil_h_Included
29+
#include "VKUtil.h"
30+
31+
#define VK_KHR_VALIDATION_LAYER_NAME "VK_LAYER_KHRONOS_validation"
32+
33+
// Named entries are layers or extensions, arragned into on-stack linked list.
34+
typedef struct VKNamedEntry {
35+
pchar name;
36+
const void* found; // Pointer to the found struct.
37+
struct VKNamedEntry* next; // Pointer to the next entry.
38+
} VKNamedEntry;
39+
40+
#define DEF_NAMED_ENTRY(LIST, NAME) VKNamedEntry NAME = { NAME ## _NAME, NULL, (LIST) }; \
41+
if (NAME.name != NULL) (LIST) = &(NAME)
42+
43+
static void VKNamedEntry_LogAll(pchar what, pchar all, uint32_t count, size_t stride) {
44+
J2dRlsTraceLn1(J2D_TRACE_VERBOSE, " Supported %s:", what)
45+
for (uint32_t i = 0; i < count; i++) {
46+
if (i == 0) J2dRlsTrace(J2D_TRACE_VERBOSE, " ")
47+
else J2dRlsTrace(J2D_TRACE_VERBOSE, ", ")
48+
J2dRlsTrace(J2D_TRACE_VERBOSE, all)
49+
all += stride;
50+
}
51+
J2dRlsTrace(J2D_TRACE_VERBOSE, "\n")
52+
}
53+
54+
static void VKNamedEntry_LogFound(const VKNamedEntry* list) {
55+
for (; list != NULL; list = list->next) {
56+
J2dRlsTraceLn2(J2D_TRACE_INFO, " %s = %s", list->name, list->found ? "true" : "false")
57+
}
58+
}
59+
60+
static void VKNamedEntry_Match(VKNamedEntry* list, pchar all, uint32_t count, size_t stride) {
61+
for (; list != NULL; list = list->next) {
62+
pchar check = all;
63+
for (uint32_t i = 0; i < count; i++) {
64+
if (strcmp(list->name, check) == 0) {
65+
list->found = check;
66+
break;
67+
}
68+
check += stride;
69+
}
70+
}
71+
}
72+
73+
static ARRAY(pchar) VKNamedEntry_CollectNames(const VKNamedEntry* list) {
74+
ARRAY(pchar) result = NULL;
75+
for (; list != NULL; list = list->next) {
76+
if (list->found) ARRAY_PUSH_BACK(result) = list->name;
77+
}
78+
return result;
79+
}
80+
81+
static void VKCapabilityUtil_LogErrors(int level, ARRAY(pchar) errors) {
82+
for (uint32_t i = 0; i < ARRAY_SIZE(errors); i++) {
83+
J2dRlsTraceLn1(level, " %s", errors[i])
84+
}
85+
}
86+
87+
#endif //VKCapabilityUtil_h_Included

0 commit comments

Comments
 (0)