Skip to content

Commit b9b7387

Browse files
author
v.andrusyshyn
committed
Continue VK JNI and WebGPU integration with Kotlin rendering module.
1 parent f1123d9 commit b9b7387

133 files changed

Lines changed: 4574 additions & 1689 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

gradle/libs.versions.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@ atomicfu = "0.29.0"
44
coreKtx = "1.13.1"
55
firebaseAnalyticsKtx = "22.5.0"
66
firebaseCrashlyticsKtx = "19.4.4"
7+
jinput = "2.0.10"
78
koin = "4.1.1"
89
kotlinxBrowser = "0.14.0"
910
kotlinxCoroutinesCore = "1.10.2"
1011
kotlinxDatetime = "0.7.1"
1112
kotlinxSerializationCore = "1.7.3"
1213
kotlinxSerializationJson = "1.6.3"
1314
ktorSerializationKotlinxJsonVersion = "3.0.0"
14-
protobuf = "3.25.3"
1515
kotlin = "2.2.10"
1616
jetbrainsKotlinJvm = "2.2.10"
1717
compose = "1.8.2"
@@ -25,6 +25,7 @@ junit = "1.3.0"
2525
[libraries]
2626
androidx-core-ktx = { group = "androidx.core", name = "core-ktx", version.ref = "coreKtx" }
2727
atomicfu = { module = "org.jetbrains.kotlinx:atomicfu", version.ref = "atomicfu" }
28+
jinput = { module = "net.java.jinput:jinput", version.ref = "jinput" }
2829
kotlinx-coroutines-core = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-core", version.ref = "kotlinxCoroutinesCore" }
2930
kotlinx-coroutines-test = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-test", version.ref = "kotlinxCoroutinesCore" }
3031
kotlinx-datetime = { module = "org.jetbrains.kotlinx:kotlinx-datetime", version.ref = "kotlinxDatetime" }
@@ -46,7 +47,6 @@ ktor-server-content-negotiation = { module = "io.ktor:ktor-server-content-negoti
4647
ktor-server-core = { module = "io.ktor:ktor-server-core", version.ref = "ktor" }
4748
ktor-server-netty = { module = "io.ktor:ktor-server-netty", version.ref = "ktor" }
4849
ktor-server-tests = { module = "io.ktor:ktor-server-tests", version.ref = "ktor" }
49-
protobuf-kotlin = { module = "com.google.protobuf:protobuf-kotlin", version.ref = "protobuf" }
5050

5151
[plugins]
5252
android-application = { id = "com.android.application", version.ref = "agp" }

kanvas-math/src/commonMain/kotlin/com/cws/kanvas/math/Mat4.kt

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -149,37 +149,37 @@ fun Mat4(
149149
return m
150150
}
151151

152-
fun Mat4.model(translation: Vec3, rx: Float, ry: Float, rz: Float, scalar: Vec3): Mat4 = stackPush {
152+
fun ModelMatrix(translation: Vec3, rx: Float, ry: Float, rz: Float, scalar: Vec3): Mat4 = stackPush {
153153
Mat4()
154154
.identity()
155155
.translate(translation)
156156
.rotate(rx, ry, rz, Vec3(1f, 1f, 1f))
157157
.scale(scalar)
158158
}
159159

160-
fun Mat4.model(translation: Vec3, quaternion: Quaternion, scalar: Vec3): Mat4 = stackPush {
160+
fun ModelMatrix(translation: Vec3, quaternion: Quaternion, scalar: Vec3): Mat4 = stackPush {
161161
Mat4()
162162
.identity()
163163
.translate(translation)
164164
.rotate(quaternion)
165165
.scale(scalar)
166166
}
167167

168-
fun Mat4.rigid(translation: Vec3, rx: Float, ry: Float, rz: Float): Mat4 = stackPush {
168+
fun RigidMatrix(translation: Vec3, rx: Float, ry: Float, rz: Float): Mat4 = stackPush {
169169
Mat4()
170170
.identity()
171171
.translate(translation)
172172
.rotate(rx, ry, rz, Vec3(1f, 1f, 1f))
173173
}
174174

175-
fun Mat4.rigid(translation: Vec3, quaternion: Quaternion): Mat4 = stackPush {
175+
fun RigidMatrix(translation: Vec3, quaternion: Quaternion): Mat4 = stackPush {
176176
Mat4()
177177
.identity()
178178
.translate(translation)
179179
.rotate(quaternion)
180180
}
181181

182-
fun Mat4.view(position: Vec3, front: Vec3, up: Vec3): Mat4 = stackPush {
182+
fun ViewMatrix(position: Vec3, front: Vec3, up: Vec3): Mat4 = stackPush {
183183
val right = cross(front, up).normalize()
184184
val f = -front
185185
val c = cross(right, front)
@@ -192,7 +192,7 @@ fun Mat4.view(position: Vec3, front: Vec3, up: Vec3): Mat4 = stackPush {
192192
return m.transpose().inverse()
193193
}
194194

195-
fun Mat4.ortho(left: Float, right: Float, bottom: Float, top: Float, zNear: Float, zFar: Float): Mat4 = stackPush {
195+
fun OrthoMatrix(left: Float, right: Float, bottom: Float, top: Float, zNear: Float, zFar: Float): Mat4 = stackPush {
196196
Mat4(
197197
2.0f / (right - left), 0.0f, 0.0f, 0.0f,
198198
0.0f, 2.0f / (bottom - top), 0.0f, 0.0f,
@@ -201,7 +201,7 @@ fun Mat4.ortho(left: Float, right: Float, bottom: Float, top: Float, zNear: Floa
201201
)
202202
}
203203

204-
fun Mat4.perspective(aspectRatio: Float, fov: Degree, zNear: Float, zFar: Float): Mat4 = stackPush {
204+
fun PerspectiveMatrix(aspectRatio: Float, fov: Degree, zNear: Float, zFar: Float): Mat4 = stackPush {
205205
val f = 1.0f / tan((fov * 0.5f).radians.value)
206206
Mat4(
207207
f / aspectRatio, 0.0f, 0.0f, 0.0f,
@@ -211,7 +211,7 @@ fun Mat4.perspective(aspectRatio: Float, fov: Degree, zNear: Float, zFar: Float)
211211
)
212212
}
213213

214-
fun Mat4.normal(): Mat4 = stackPush {
214+
fun NormalMatrix(): Mat4 = stackPush {
215215
return Mat4()
216216
.identity()
217217
.inverse()
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package com.cws.kanvas.math
2+
3+
data class Transform(
4+
var position: Vec3 = Vec3(),
5+
var rotation: Vec3 = Vec3(),
6+
var scale: Vec3 = Vec3(),
7+
) {
8+
fun toMat4(): Mat4 = ModelMatrix(position, rotation.x, rotation.y, rotation.z, scale)
9+
}

kanvas-rendering/src/commonMain/kotlin/com/cws/kanvas/rendering/backend/Attribute.kt

Lines changed: 0 additions & 24 deletions
This file was deleted.
Lines changed: 10 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,16 @@
11
package com.cws.kanvas.rendering.backend
22

3-
expect enum class BindingType {
4-
UNIFORM_BUFFER,
5-
STORAGE_BUFFER,
6-
TEXTURE,
7-
SAMPLER,
8-
}
9-
10-
interface BindingResource
11-
12-
data class Binding(
13-
var type: BindingType,
14-
var shaderStages: Int,
15-
var set: Int,
16-
var binding: Int,
17-
var count: Int = 1,
18-
var resource: BindingResource? = null
19-
)
20-
21-
data class BindingLayoutInfo(
22-
val name: String,
23-
val bindings: List<Binding>,
24-
)
25-
26-
expect class BindingLayoutHandle
3+
import com.cws.std.memory.INativeData
4+
import com.cws.std.memory.MemoryLayout
5+
import com.cws.std.memory.NativeBuffer
276

28-
expect class BindingLayout(renderContext: RenderContext, info: BindingLayoutInfo) : Resource<BindingLayoutHandle> {
29-
val info: BindingLayoutInfo
7+
expect class BindingLayout(context: RenderContext, info: BindingInfo)
8+
: Resource<BindingLayoutHandle, BindingInfo>, INativeData {
309
override fun onCreate()
3110
override fun onDestroy()
32-
fun update()
11+
override fun setInfo()
12+
override val buffer: NativeBuffer?
13+
override fun sizeBytes(layout: MemoryLayout): Int
14+
override fun pack(buffer: NativeBuffer)
15+
override fun unpack(buffer: NativeBuffer): INativeData
3316
}

kanvas-rendering/src/commonMain/kotlin/com/cws/kanvas/rendering/backend/Blend.kt

Lines changed: 0 additions & 32 deletions
This file was deleted.

kanvas-rendering/src/commonMain/kotlin/com/cws/kanvas/rendering/backend/Buffer.kt

Lines changed: 5 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -2,33 +2,10 @@ package com.cws.kanvas.rendering.backend
22

33
import com.cws.std.memory.NativeBuffer
44

5-
expect enum class BufferUsage {
6-
TRANSFER_SRC,
7-
TRANSFER_DST,
8-
UNIFORM_TEXEL,
9-
STORAGE_TEXEL,
10-
UNIFORM_BUFFER,
11-
STORAGE_BUFFER,
12-
INDEX_BUFFER,
13-
VERTEX_BUFFER,
14-
INDIRECT_BUFFER;
15-
16-
val value: Int
17-
};
18-
19-
data class BufferInfo(
20-
val usages: Int,
21-
val size: Long,
22-
val memoryType: MemoryType,
23-
)
24-
25-
expect class BufferHandle
26-
27-
expect open class Buffer(context: RenderContext, info: BufferInfo) : Resource<BufferHandle> {
5+
expect open class Buffer(context: RenderContext, info: BufferInfo) : Resource<BufferHandle, BufferInfo> {
286
override fun onCreate()
297
override fun onDestroy()
30-
31-
fun write(data: NativeBuffer, srcOffset: Int, destOffset: Int, size: Int)
32-
fun read(data: NativeBuffer, srcOffset: Int, destOffset: Int, size: Int)
33-
fun update()
34-
}
8+
override fun setInfo()
9+
fun write(frame: Int, data: NativeBuffer, srcOffset: Int, destOffset: Int, size: Int)
10+
fun read(frame: Int, data: NativeBuffer, srcOffset: Int, destOffset: Int, size: Int)
11+
}
Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,55 @@
11
package com.cws.kanvas.rendering.backend
22

3-
expect class CommandBuffer(context: RenderContext) {
3+
import com.cws.std.memory.NativeDataList
44

5+
expect class CommandBuffer(
6+
context: RenderContext,
7+
handle: CommandBufferHandle,
8+
) {
9+
var handle: CommandBufferHandle?
10+
11+
fun reset()
12+
13+
fun begin()
14+
fun end()
15+
16+
fun beginRenderPass(renderTarget: RenderTargetHandle, colorAttachmentIndex: Int)
17+
fun endRenderPass()
18+
19+
fun setPipeline(pipeline: RenderPipeline)
20+
fun setViewport(
21+
x: Float, y: Float,
22+
width: Float, height: Float,
23+
minDepth: Float, maxDepth: Float,
24+
)
25+
fun setScissor(
26+
x: Int, y: Int,
27+
width: Int, height: Int,
28+
)
29+
30+
fun addSecondaryBuffer(secondaryBuffer: CommandBufferHandle)
31+
fun addSecondaryBuffers(secondaryBuffers: NativeDataList<CommandBufferHandle>)
32+
33+
fun draw(vertices: Int, vertexOffset: Int, instances: Int, instanceOffset: Int)
34+
35+
fun drawIndexed(vertices: Int, vertexOffset: Int,
36+
indices: Int, indexOffset: Int,
37+
instances: Int, instanceOffset: Int)
38+
39+
fun drawIndexedIndirect(indirectBuffer: BufferHandle, offset: Int, drawCount: Int)
40+
41+
fun copyBufferToBuffer(srcBuffer: BufferHandle, dstBuffer: BufferHandle,
42+
srcOffset: Int, dstOffset: Int, size: Int)
43+
44+
fun copyBufferToImage(srcBuffer: BufferHandle, dstImage: TextureHandle,
45+
dstMipLevel: Int, dstWidth: Int, dstHeight: Int, dstDepth: Int)
46+
47+
fun copyImageToBuffer(srcImage: TextureHandle, dstBuffer: BufferHandle,
48+
srcX: Int, srcY: Int, srcZ: Int, dstOffset: Int,
49+
width: Int, height: Int, depth: Int)
50+
51+
fun copyImageToImage(srcImage: TextureHandle, dstImage: TextureHandle,
52+
srcX: Int, srcY: Int, srcZ: Int,
53+
dstX: Int, dstY: Int, dstZ: Int,
54+
width: Int, height: Int, depth: Int)
555
}

0 commit comments

Comments
 (0)