Skip to content

Commit

Permalink
[Vulkan] Fix enum
Browse files Browse the repository at this point in the history
  • Loading branch information
squid233 committed Apr 14, 2024
1 parent 260ae89 commit acc4764
Show file tree
Hide file tree
Showing 12 changed files with 64 additions and 56 deletions.
1 change: 0 additions & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,6 @@ artifactNameMap.forEach { (subprojectName, artifactName) ->
allprojects {
tasks.withType<Javadoc> {
options {
verbose()
if (this is CoreJavadocOptions) {
if (jdkEnablePreview.toBoolean()) {
addBooleanOption("-enable-preview", true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,11 @@ import kotlin.io.path.Path
val UPPERCASE = Regex("([A-Z])")

fun indent(indent: Int) = " ".repeat(indent)
fun removeConstPrefix(string: String) = string.removePrefix("VK_")
fun String.removeConstPrefix(): String {
val s = this.removePrefix("VK_")
return if (!s.first().isJavaIdentifierStart()) "_$s" else s
}

fun formatNumber(string: String) = string
.removeSurrounding("(", ")")
.removeSuffix("LL")
Expand Down Expand Up @@ -161,13 +165,13 @@ class VKFile(
* @since 0.1.0
*/
fun main() {
val VK10 = VKFile(
"VK10", document = """
val Vk10 = VKFile(
"Vk10", document = """
The Vulkan binding.
@since 0.1.0
""".trimIndent()
)
VK10.superclasses.add("overrun.marshal.DirectAccess")
Vk10.superclasses.add("overrun.marshal.DirectAccess")

val builder = DocumentBuilderFactory.newInstance().newDocumentBuilder()
ClassLoader.getSystemResourceAsStream("vk.xml")!!.use { stream ->
Expand All @@ -183,8 +187,11 @@ fun main() {
}
}

fun endsWithVendor(string: String) =
vendors.firstOrNull(string::endsWith)

fun removeVendorSuffix(string: String) =
vendors.firstOrNull { string.endsWith(it) }
endsWithVendor(string)
?.let { string.removeSuffix(it) }
?: string

Expand All @@ -196,8 +203,8 @@ fun main() {
enumsNode.childNodes.forEach { node ->
if (node.nodeName == "enum") {
val attrib = node.attributes
val name = removeConstPrefix(attrib["name"].nodeValue)
val alias = attrib["alias"]?.nodeValue?.let { removeConstPrefix(it) }
val name = attrib["name"].nodeValue.removeConstPrefix()
val alias = attrib["alias"]?.nodeValue?.removeConstPrefix()
if (alias != null) {
list.add(Constant(list.find { it.name == alias }!!.type, name, alias))
} else {
Expand All @@ -206,14 +213,15 @@ fun main() {
}
}
}
list.forEach(VK10::addComponent)
list.forEach(Vk10::addComponent)
}

else -> {
when (attributes["type"].nodeValue) {
"enum" -> {
val clazz = VKFile(enumName, classType = "enum")
clazz.superinterfaces.add("overrun.marshal.CEnum")
val endsWithVendor = endsWithVendor(enumName) != null
val prefix = "${
removeVendorSuffix(enumName)
.replace(UPPERCASE) { "_${it.groupValues[1]}" }
Expand All @@ -224,14 +232,15 @@ fun main() {
if (node.nodeName == "enum") {
val attrib = node.attributes
val name =
removeVendorSuffix(attrib["name"].nodeValue.removePrefix(prefix))
attrib["name"].nodeValue.removePrefix(prefix)
.let { if (endsWithVendor) removeVendorSuffix(it) else it }
.removeSuffix("_")
.removePrefix("VK_")
.removeConstPrefix()
val alias = attrib["alias"]?.nodeValue
?.removePrefix(prefix)
?.let { removeVendorSuffix(it) }
?.let { if (endsWithVendor) removeVendorSuffix(it) else it }
?.removeSuffix("_")
?.removePrefix("VK_")
?.removeConstPrefix()
if (alias != null) {
clazz.addComponent(
EnumValue(
Expand Down Expand Up @@ -268,7 +277,7 @@ fun main() {
}
}
}
VK10.generate()
Vk10.generate()
}

private inline fun NodeList.forEach(action: (Node) -> Unit) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
* The Vulkan binding.
* @since 0.1.0
*/
public interface VK10 extends overrun.marshal.DirectAccess {
public interface Vk10 extends overrun.marshal.DirectAccess {
int MAX_PHYSICAL_DEVICE_NAME_SIZE = 256;
int UUID_SIZE = 16;
int LUID_SIZE = 8;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
package overrungl.vulkan;

public enum VkDisplacementMicromapFormatNV implements overrun.marshal.CEnum {
64_TRIANGLES_64_BYTES(1),
256_TRIANGLES_128_BYTES(2),
1024_TRIANGLES_128_BYTES(3),
_64_TRIANGLES_64_BYTES(1),
_256_TRIANGLES_128_BYTES(2),
_1024_TRIANGLES_128_BYTES(3),
;
private final int value;
VkDisplacementMicromapFormatNV(int value) { this.value = value; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public enum VkDriverId implements overrun.marshal.CEnum {
/**
* Intel Corporation
*/
INTEL_OPEN_SOURCE(6),
INTEL_OPEN_SOURCE_MESA(6),
/**
* Imagination Technologies
*/
Expand Down Expand Up @@ -117,7 +117,7 @@ public enum VkDriverId implements overrun.marshal.CEnum {
/**
* Imagination Technologies
*/
IMAGINATION_OPEN_SOURCE(25),
IMAGINATION_OPEN_SOURCE_MESA(25),
/**
* Mesa open source project
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,17 @@
package overrungl.vulkan;

public enum VkFragmentShadingRateNV implements overrun.marshal.CEnum {
1_INVOCATION_PER_PIXEL(0),
1_INVOCATION_PER_1X2_PIXELS(1),
1_INVOCATION_PER_2X1_PIXELS(4),
1_INVOCATION_PER_2X2_PIXELS(5),
1_INVOCATION_PER_2X4_PIXELS(6),
1_INVOCATION_PER_4X2_PIXELS(9),
1_INVOCATION_PER_4X4_PIXELS(10),
2_INVOCATIONS_PER_PIXEL(11),
4_INVOCATIONS_PER_PIXEL(12),
8_INVOCATIONS_PER_PIXEL(13),
16_INVOCATIONS_PER_PIXEL(14),
_1_INVOCATION_PER_PIXEL(0),
_1_INVOCATION_PER_1X2_PIXELS(1),
_1_INVOCATION_PER_2X1_PIXELS(4),
_1_INVOCATION_PER_2X2_PIXELS(5),
_1_INVOCATION_PER_2X4_PIXELS(6),
_1_INVOCATION_PER_4X2_PIXELS(9),
_1_INVOCATION_PER_4X4_PIXELS(10),
_2_INVOCATIONS_PER_PIXEL(11),
_4_INVOCATIONS_PER_PIXEL(12),
_8_INVOCATIONS_PER_PIXEL(13),
_16_INVOCATIONS_PER_PIXEL(14),
NO_INVOCATIONS(15),
;
private final int value;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
package overrungl.vulkan;

public enum VkImageType implements overrun.marshal.CEnum {
1D(0),
2D(1),
3D(2),
_1D(0),
_2D(1),
_3D(2),
;
private final int value;
VkImageType(int value) { this.value = value; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@
package overrungl.vulkan;

public enum VkImageViewType implements overrun.marshal.CEnum {
1D(0),
2D(1),
3D(2),
_1D(0),
_2D(1),
_3D(2),
CUBE(3),
1D_ARRAY(4),
2D_ARRAY(5),
_1D_ARRAY(4),
_2D_ARRAY(5),
CUBE_ARRAY(6),
;
private final int value;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
package overrungl.vulkan;

public enum VkOpacityMicromapFormatEXT implements overrun.marshal.CEnum {
2_STATE(1),
4_STATE(2),
_2_STATE(1),
_4_STATE(2),
;
private final int value;
VkOpacityMicromapFormatEXT(int value) { this.value = value; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
package overrungl.vulkan;

public enum VkShaderFloatControlsIndependence implements overrun.marshal.CEnum {
32_BIT_ONLY(0),
_32_BIT_ONLY(0),
ALL(1),
NONE(2),
;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,17 @@

public enum VkShadingRatePaletteEntryNV implements overrun.marshal.CEnum {
NO_INVOCATIONS(0),
16_INVOCATIONS_PER_PIXEL(1),
8_INVOCATIONS_PER_PIXEL(2),
4_INVOCATIONS_PER_PIXEL(3),
2_INVOCATIONS_PER_PIXEL(4),
1_INVOCATION_PER_PIXEL(5),
1_INVOCATION_PER_2X1_PIXELS(6),
1_INVOCATION_PER_1X2_PIXELS(7),
1_INVOCATION_PER_2X2_PIXELS(8),
1_INVOCATION_PER_4X2_PIXELS(9),
1_INVOCATION_PER_2X4_PIXELS(10),
1_INVOCATION_PER_4X4_PIXELS(11),
_16_INVOCATIONS_PER_PIXEL(1),
_8_INVOCATIONS_PER_PIXEL(2),
_4_INVOCATIONS_PER_PIXEL(3),
_2_INVOCATIONS_PER_PIXEL(4),
_1_INVOCATION_PER_PIXEL(5),
_1_INVOCATION_PER_2X1_PIXELS(6),
_1_INVOCATION_PER_1X2_PIXELS(7),
_1_INVOCATION_PER_2X2_PIXELS(8),
_1_INVOCATION_PER_4X2_PIXELS(9),
_1_INVOCATION_PER_2X4_PIXELS(10),
_1_INVOCATION_PER_4X4_PIXELS(11),
;
private final int value;
VkShadingRatePaletteEntryNV(int value) { this.value = value; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ public enum VkVendorId implements overrun.marshal.CEnum {
/**
* Vivante vendor ID
*/
(0x10001),
VIV(0x10001),
/**
* VeriSilicon vendor ID
*/
(0x10002),
VSI(0x10002),
/**
* Kazan Software Renderer
*/
Expand All @@ -37,7 +37,7 @@ public enum VkVendorId implements overrun.marshal.CEnum {
/**
* Mesa vendor ID
*/
(0x10005),
MESA(0x10005),
/**
* PoCL vendor ID
*/
Expand Down

0 comments on commit acc4764

Please sign in to comment.