Skip to content

Commit

Permalink
Merge pull request #68 from Over-Run/vulkan
Browse files Browse the repository at this point in the history
  • Loading branch information
squid233 authored Jan 9, 2025
2 parents fd5408d + d29ab5f commit fe9f316
Show file tree
Hide file tree
Showing 1,721 changed files with 384,220 additions and 1,146 deletions.
14 changes: 8 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,10 @@ The customizer has already included this.

### Khronos APIs

| Library | Description |
|-------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------|
| [OpenGL](https://www.khronos.org/opengl/) | The most widely adopted 2D and 3D graphics API in the industry, bringing thousands of applications to a wide variety of computer platforms. |
| Library | Description |
|-------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [OpenGL](https://www.khronos.org/opengl/) | The most widely adopted 2D and 3D graphics API in the industry, bringing thousands of applications to a wide variety of computer platforms. |
| [Vulkan](https://www.khronos.org/vulkan/) | A new generation graphics and compute API that provides high-efficiency, cross-platform access to modern GPUs used in a wide variety of devices from PCs and consoles to mobile phones and embedded platforms. |

### Display and Input

Expand All @@ -89,9 +90,10 @@ The customizer has already included this.

### Audio

| Library | Description |
|-----------------------------------|------------------------------------------------------------------------------------------------------------------------|
| [OpenAL](https://www.openal.org/) | A cross-platform 3D audio API appropriate for use with gaming applications and many other types of audio applications. |
| Library | Description |
|-----------------------------------------|------------------------------------------------------------------------------------------------------------------------|
| [OpenAL](https://www.openal.org/) | A cross-platform 3D audio API appropriate for use with gaming applications and many other types of audio applications. |
| [OpenAL Soft](https://openal-soft.org/) | An LGPL-licensed, cross-platform, software implementation of the OpenAL 3D audio API. |

### [stb](https://github.com/nothings/stb) - single-file public domain libraries for C/C++

Expand Down
8 changes: 5 additions & 3 deletions buildSrc/src/main/kotlin/natives.kt
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,11 @@ enum class Artifact(
"Single-file public domain libraries for fonts, images, ogg vorbis files and more.",
":stb"
),
// VULKAN("overrungl-vulkan", "OverrunGL - Vulkan bindings",
// "A new generation graphics and compute API that provides high-efficiency, cross-platform access to modern GPUs used in a wide variety of devices from PCs and consoles to mobile phones and embedded platforms.",
// ":vulkan", "Vulkan", null),
VULKAN(
"OverrunGL - Vulkan bindings",
"A new generation graphics and compute API that provides high-efficiency, cross-platform access to modern GPUs used in a wide variety of devices from PCs and consoles to mobile phones and embedded platforms.",
":vulkan"
),
}

fun nativeFileName(nativeBinding: NativeBinding, platform: NativePlatform): String {
Expand Down
4 changes: 3 additions & 1 deletion doc/customizer/doc_on_customizer.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
# The Modules Customizer

This documentation is for customizer in version 0.6.0.

## Introduction

The modules customizer is provided in order to comfort the start of users' development.

## Selecting Version

Only the latest snapshot version is provided.
The latest pre-release and snapshot version are provided.

## Selecting Modules

Expand Down
1 change: 1 addition & 0 deletions doc/notes/0.x/0.1.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ This version includes the following features:
- Native memory access for JOML
- Native File Dialog Extended
- OpenAL and extensions
- Vulkan and extensions
10 changes: 5 additions & 5 deletions generators/glfw/src/main/kotlin/overrungl/glfw/GLFWGenerator.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ package overrungl.glfw
import com.palantir.javapoet.TypeName
import overrungl.gen.*

val glfwPackage = "overrungl.glfw"
val glfwLookup = "GLFWInternal.lookup()"
const val glfwPackage = "overrungl.glfw"
const val glfwLookup = "GLFWInternal.lookup()"

val glfw_boolean = CustomTypeSpec(
carrier = TypeName.INT,
Expand Down Expand Up @@ -186,8 +186,8 @@ fun main() {
}.pointerType c "const GLFWimage*"

val GLFWgamepadstate_ptr = Struct(glfwPackage, "GLFWGamepadState", cType = "GLFWgamepadstate") {
fixedSize(uchar, "buttons", 15)
fixedSize(float, "axes", 6)
fixedSize(uchar, "buttons", "15")
fixedSize(float, "axes", "6")
}.pointerType c "GLFWgamepadstate*"

val const_GLFWallocator_ptr = Struct(glfwPackage, "GLFWAllocator", cType = "GLFWallocator") {
Expand Down Expand Up @@ -1136,7 +1136,7 @@ fun main() {
"glfwGetX11Display"(Display_ptr, entrypoint = "glfwGetX11Display", optional = true)
"glfwGetX11Adapter"(RRCrtc, GLFWmonitor_ptr("monitor"), entrypoint = "glfwGetX11Adapter", optional = true)
"glfwGetX11Monitor"(RROutput, GLFWmonitor_ptr("monitor"), entrypoint = "glfwGetX11Monitor", optional = true)
"glfwGetX11Window"(RROutput, GLFWwindow_ptr("window"), entrypoint = "glfwGetX11Window", optional = true)
"glfwGetX11Window"(Window, GLFWwindow_ptr("window"), entrypoint = "glfwGetX11Window", optional = true)
+"glfwSetX11SelectionString"(
void,
const_char_ptr("string"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import kotlin.io.path.createDirectories

private val recordingErrorType = mutableSetOf<String>()

val openglPackage = "overrungl.opengl"
const val openglPackage = "overrungl.opengl"
fun extPackage(vendor: String): String {
val lowercase = vendor.lowercase()
if (lowercase == "3dfx") return "$openglPackage.threedfx"
Expand Down
43 changes: 33 additions & 10 deletions generators/src/main/kotlin/overrungl/gen/Struct.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,15 @@ package overrungl.gen

import com.palantir.javapoet.ArrayTypeName
import com.palantir.javapoet.ClassName
import java.nio.file.Files
import kotlin.io.path.Path

class Struct(
private val packageName: String,
private val name: String,
private val cType: String? = null,
private val opaque: Boolean = false,
private val union: Boolean = false,
action: Struct.() -> Unit
) {
private val members = mutableListOf<StructMember>()
Expand All @@ -51,6 +53,7 @@ class Struct(
}
private var doLast: (StringBuilder) -> Unit = {}
val byValue: ByValueWrapper by lazy { ByValueWrapper(this) }
val imports = mutableListOf<String>()

@JvmInline
value class ByValueWrapper(val struct: Struct)
Expand All @@ -72,7 +75,7 @@ class Struct(
members.add(ByValueStructStructMember(this.struct, name))
}

fun fixedSize(type: CustomTypeSpec, name: String, size: Long) {
fun fixedSize(type: CustomTypeSpec, name: String, size: String) {
members.add(FixedSizeStructMember(type, size, name))
}

Expand All @@ -89,9 +92,12 @@ class Struct(
import overrungl.annotation.*;
import overrungl.struct.*;
import overrungl.util.*;
""".trimIndent()
)
imports.forEach {
sb.appendLine("import $it;")
}
sb.appendLine()

// javadoc
sb.appendLine("/// ## Members")
Expand All @@ -102,7 +108,7 @@ class Struct(
when (it) {
is ValueStructMember -> "/// [VarHandle][#VH_${it.name}] - [Getter][#${it.name}()] - [Setter][#${it.name}(${it.type.carrier})]"
is ByValueStructStructMember -> "/// [Byte offset][#OFFSET_${it.name}] - [Memory layout][#ML_${it.name}] - [Getter][#${it.name}()] - [Setter][#${it.name}(${it.type.carrier})]"
is FixedSizeStructMember -> "/// [Byte offset handle][#MH_${it.name}] - [Memory layout][#ML_${it.name}] - Getter - Setter"
is FixedSizeStructMember -> "/// [Byte offset handle][#MH_${it.name}] - [Memory layout][#ML_${it.name}] - [Getter][#${it.name}(long)] - [Setter][#${it.name}(long, ${it.type.carrier})]"
}
)
}
Expand All @@ -112,7 +118,7 @@ class Struct(
/// ## Layout
/// [Java definition][#LAYOUT]
/// ```c
/// typedef struct ${if (cType != null) "$cType " else ""}{
/// typedef ${if (union) "union" else "struct"} ${if (cType != null) "$cType " else ""}{
""".trimIndent()
)
members.forEach {
Expand All @@ -127,9 +133,9 @@ class Struct(

sb.appendLine(
"""
public final class $name extends Struct {
/// The struct layout of `$cType`.
public static final StructLayout LAYOUT = LayoutBuilder.struct(
public final class $name extends ${if (union) "Union" else "Struct"} {
/// The ${if (union) "union" else "struct"} layout of `$cType`.
public static final ${if (union) "Union" else "Struct"}Layout LAYOUT = ${if (union) "MemoryLayout.unionLayout" else "LayoutBuilder.struct"}(
""".trimIndent()
)
sb.appendLine(members.joinToString(",\n") {
Expand Down Expand Up @@ -182,6 +188,21 @@ class Struct(
| /// @return the created instance or `null` if the segment is `NULL`
| public static $name of(MemorySegment segment) { return Unmarshal.isNullPointer(segment) ? null : new $name(segment); }
|
| /// Creates `$name` with the given segment.
| ///
| /// Reinterprets the segment if zero-length.
| /// @param segment the memory segment
| /// @return the created instance or `null` if the segment is `NULL`
| public static $name ofNative(MemorySegment segment) { return Unmarshal.isNullPointer(segment) ? null : new $name(segment.byteSize() == 0 ? segment.reinterpret(LAYOUT.byteSize()) : segment); }
|
| /// Creates `$name` with the given segment.
| ///
| /// Reinterprets the segment if zero-length.
| /// @param segment the memory segment
| /// @param count the count of the buffer
| /// @return the created instance or `null` if the segment is `NULL`
| public static $name ofNative(MemorySegment segment, long count) { return Unmarshal.isNullPointer(segment) ? null : new $name(segment.byteSize() == 0 ? segment.reinterpret(LAYOUT.scale(0, count)) : segment); }
|
""".trimMargin()
)

Expand Down Expand Up @@ -391,7 +412,9 @@ class Struct(
doLast.invoke(sb)
sb.appendLine("}")

writeString(Path(packageName.replace('.', '/'), "$name.java"), sb.toString())
val base = Path(packageName.replace('.', '/'))
Files.createDirectories(base)
writeString(base.resolve("$name.java"), sb.toString())
}
}

Expand All @@ -414,15 +437,15 @@ data class ByValueStructStructMember(

data class FixedSizeStructMember(
val componentType: CustomTypeSpec,
val size: Long,
val size: String,
override val name: String
) : StructMember {
override val type: CustomTypeSpec
get() = CustomTypeSpec(
carrier = MemorySegment_,
javaType = ArrayTypeName.of(componentType.javaType),
processor = IdentityValueProcessor,
layout = "MemoryLayout.sequenceLayout(${size}L, ${componentType.layout})",
layout = "MemoryLayout.sequenceLayout(${size}, ${componentType.layout})",
cType = "${componentType.cType}[$size]",
allocatorRequirement = AllocatorRequirement.STACK
)
Expand Down
5 changes: 4 additions & 1 deletion generators/src/main/kotlin/overrungl/gen/Upcall.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package overrungl.gen

import com.palantir.javapoet.ClassName
import com.palantir.javapoet.TypeName
import java.nio.file.Files
import kotlin.io.path.Path

fun generateUpcallType(packageName: String, name: String): CustomTypeSpec {
Expand Down Expand Up @@ -74,7 +75,6 @@ class Upcall(
.reduceOrNull(AllocatorRequirement::stricter)
?: AllocatorRequirement.NO

val path = Path("${packageName.replace('.', '/')}/$name.java")
val sb = StringBuilder()

sb.appendLine(commentedFileHeader)
Expand Down Expand Up @@ -301,6 +301,9 @@ class Upcall(

sb.appendLine("}")

val base = Path(packageName.replace('.', '/'))
Files.createDirectories(base)
val path = base.resolve("$name.java")
writeString(path, sb.toString())
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ fun STBRectPack() {
int("num_nodes")
stbrp_node_ptr("active_head")
stbrp_node_ptr("free_head")
fixedSize(stbrp_node.byValueType, "extra", 2)
fixedSize(stbrp_node.byValueType, "extra", "2")
}.pointerType c "stbrp_context *"

StaticDowncall(stbPackage, "STBRectPack", symbolLookup = stbLookup) {
Expand Down
5 changes: 1 addition & 4 deletions generators/vulkan/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,4 @@ dependencies {
implementation(project(":generators"))
}

/*tasks.register<GenerateTask>("generate") {
mainClass.set("overrungl.vulkan.VulkanGeneratorKt")
workingDir = project(":vulkan").projectDir.resolve("src/main/java/overrungl/vulkan")
}*/
registerGenerateTask("overrungl.vulkan.VulkanGeneratorKt", ":vulkan")
Loading

0 comments on commit fe9f316

Please sign in to comment.