From 9ec0882c358273c0598ba83c0199d529c27b6bea Mon Sep 17 00:00:00 2001 From: Dominic Fischer Date: Sun, 28 Jun 2020 16:28:26 +0100 Subject: [PATCH] Rename `ByteBuffer` to `DirectMemory` --- buildSrc/src/main/kotlin/codegen/Types.kt | 2 +- .../kotlin/codegen/vulkan/GenerateVulkan.kt | 4 +- .../commonMain/kotlin/com/kgl/core/Buffer.kt | 5 -- .../kotlin/com/kgl/core/BufferUtils.kt | 4 -- .../kotlin/com/kgl/core/ByteBuffer.kt | 21 -------- .../kotlin/com/kgl/core/DirectMemory.kt | 20 ++++++++ .../kotlin/com/kgl/core/MemUtils.kt | 4 ++ .../jsMain/kotlin/com/kgl/core/BufferUtils.kt | 8 --- .../jsMain/kotlin/com/kgl/core/ByteBuffer.kt | 45 ---------------- .../kotlin/com/kgl/core/DirectMemory.kt | 42 +++++++++++++++ .../jsMain/kotlin/com/kgl/core/MemUtils.kt | 11 ++++ .../jvmMain/kotlin/com/kgl/core/ByteBuffer.kt | 51 ------------------- .../kotlin/com/kgl/core/DirectMemory.kt | 50 ++++++++++++++++++ .../kgl/core/{BufferUtils.kt => MemUtils.kt} | 4 +- .../kotlin/com/kgl/core/ByteBuffer.kt | 49 ------------------ .../kotlin/com/kgl/core/DirectMemory.kt | 48 +++++++++++++++++ .../kgl/core/{BufferUtils.kt => MemUtils.kt} | 4 +- .../commonMain/kotlin/com/kgl/glfw/Image.kt | 4 +- .../kotlin/com/kgl/stb/STBIOCallbacks.kt | 4 +- .../commonMain/kotlin/com/kgl/stb/STBImage.kt | 16 +++--- .../jvmMain/kotlin/com/kgl/stb/STBImage.kt | 24 ++++----- .../nativeMain/kotlin/com/kgl/stb/STBImage.kt | 24 ++++----- .../vulkan/handles/AccelerationStructureNV.kt | 4 +- .../com/kgl/vulkan/handles/CommandBuffer.kt | 10 ++-- .../com/kgl/vulkan/handles/DescriptorSet.kt | 4 +- .../kotlin/com/kgl/vulkan/handles/Device.kt | 10 ++-- .../com/kgl/vulkan/handles/DeviceMemory.kt | 4 +- .../kotlin/com/kgl/vulkan/handles/Pipeline.kt | 6 +-- .../com/kgl/vulkan/handles/PipelineCache.kt | 4 +- .../com/kgl/vulkan/handles/QueryPool.kt | 4 +- .../kgl/vulkan/handles/ValidationCacheEXT.kt | 4 +- .../vulkan/handles/AccelerationStructureNV.kt | 4 +- .../com/kgl/vulkan/handles/CommandBuffer.kt | 10 ++-- .../com/kgl/vulkan/handles/DescriptorSet.kt | 4 +- .../kotlin/com/kgl/vulkan/handles/Device.kt | 10 ++-- .../com/kgl/vulkan/handles/DeviceMemory.kt | 6 +-- .../kotlin/com/kgl/vulkan/handles/Pipeline.kt | 6 +-- .../com/kgl/vulkan/handles/PipelineCache.kt | 4 +- .../com/kgl/vulkan/handles/QueryPool.kt | 4 +- .../kgl/vulkan/handles/ValidationCacheEXT.kt | 4 +- .../vulkan/handles/AccelerationStructureNV.kt | 4 +- .../com/kgl/vulkan/handles/CommandBuffer.kt | 10 ++-- .../com/kgl/vulkan/handles/DescriptorSet.kt | 4 +- .../kotlin/com/kgl/vulkan/handles/Device.kt | 10 ++-- .../com/kgl/vulkan/handles/DeviceMemory.kt | 6 +-- .../kotlin/com/kgl/vulkan/handles/Pipeline.kt | 6 +-- .../com/kgl/vulkan/handles/PipelineCache.kt | 4 +- .../com/kgl/vulkan/handles/QueryPool.kt | 4 +- .../kgl/vulkan/handles/ValidationCacheEXT.kt | 4 +- 49 files changed, 295 insertions(+), 303 deletions(-) delete mode 100644 kgl-core/src/commonMain/kotlin/com/kgl/core/Buffer.kt delete mode 100644 kgl-core/src/commonMain/kotlin/com/kgl/core/BufferUtils.kt delete mode 100644 kgl-core/src/commonMain/kotlin/com/kgl/core/ByteBuffer.kt create mode 100644 kgl-core/src/commonMain/kotlin/com/kgl/core/DirectMemory.kt create mode 100644 kgl-core/src/commonMain/kotlin/com/kgl/core/MemUtils.kt delete mode 100644 kgl-core/src/jsMain/kotlin/com/kgl/core/BufferUtils.kt delete mode 100644 kgl-core/src/jsMain/kotlin/com/kgl/core/ByteBuffer.kt create mode 100644 kgl-core/src/jsMain/kotlin/com/kgl/core/DirectMemory.kt create mode 100644 kgl-core/src/jsMain/kotlin/com/kgl/core/MemUtils.kt delete mode 100644 kgl-core/src/jvmMain/kotlin/com/kgl/core/ByteBuffer.kt create mode 100644 kgl-core/src/jvmMain/kotlin/com/kgl/core/DirectMemory.kt rename kgl-core/src/jvmMain/kotlin/com/kgl/core/{BufferUtils.kt => MemUtils.kt} (58%) delete mode 100644 kgl-core/src/nativeMain/kotlin/com/kgl/core/ByteBuffer.kt create mode 100644 kgl-core/src/nativeMain/kotlin/com/kgl/core/DirectMemory.kt rename kgl-core/src/nativeMain/kotlin/com/kgl/core/{BufferUtils.kt => MemUtils.kt} (57%) diff --git a/buildSrc/src/main/kotlin/codegen/Types.kt b/buildSrc/src/main/kotlin/codegen/Types.kt index 717b44d..81689d3 100644 --- a/buildSrc/src/main/kotlin/codegen/Types.kt +++ b/buildSrc/src/main/kotlin/codegen/Types.kt @@ -20,7 +20,7 @@ import com.squareup.kotlinpoet.MemberName internal val VIRTUAL_STACK = ClassName("com.kgl.core", "VirtualStack") -internal val BYTE_BUFFER = ClassName("com.kgl.core", "ByteBuffer") +internal val DIRECT_BUFFER = ClassName("com.kgl.core", "DirectMemory") internal val C_OPAQUE_POINTER = ClassName("kotlinx.cinterop", "COpaquePointer") internal val BYTE_VAR = ClassName("kotlinx.cinterop", "ByteVar") diff --git a/buildSrc/src/main/kotlin/codegen/vulkan/GenerateVulkan.kt b/buildSrc/src/main/kotlin/codegen/vulkan/GenerateVulkan.kt index 6fa3fdc..1b1c297 100644 --- a/buildSrc/src/main/kotlin/codegen/vulkan/GenerateVulkan.kt +++ b/buildSrc/src/main/kotlin/codegen/vulkan/GenerateVulkan.kt @@ -845,7 +845,7 @@ open class GenerateVulkan : DefaultTask() { 1 -> { when(typeName) { "char" -> STRING - "void" -> if (len.isNotEmpty()) BYTE_BUFFER else LONG + "void" -> if (len.isNotEmpty()) DIRECT_BUFFER else LONG else -> { val mainType = kglClassMap[typeName] ?: TODO("$type has no KGL representation.") arrayClassesMap[typeName] ?: collectionType.parameterizedBy(mainType) @@ -1458,7 +1458,7 @@ open class GenerateVulkan : DefaultTask() { } val isOptional = member.optional || lengthParam?.optional == true if (lengthParam != null) { - addParameter(memberNameKt, BYTE_BUFFER.copy(nullable = isOptional)) + addParameter(memberNameKt, DIRECT_BUFFER.copy(nullable = isOptional)) val assert = if (isOptional) "?" else "" if (platform == Platform.JVM) { diff --git a/kgl-core/src/commonMain/kotlin/com/kgl/core/Buffer.kt b/kgl-core/src/commonMain/kotlin/com/kgl/core/Buffer.kt deleted file mode 100644 index c531814..0000000 --- a/kgl-core/src/commonMain/kotlin/com/kgl/core/Buffer.kt +++ /dev/null @@ -1,5 +0,0 @@ -package com.kgl.core - -interface Buffer { - val size: ULong -} diff --git a/kgl-core/src/commonMain/kotlin/com/kgl/core/BufferUtils.kt b/kgl-core/src/commonMain/kotlin/com/kgl/core/BufferUtils.kt deleted file mode 100644 index b8815c3..0000000 --- a/kgl-core/src/commonMain/kotlin/com/kgl/core/BufferUtils.kt +++ /dev/null @@ -1,4 +0,0 @@ -package com.kgl.core - - -expect inline fun withByteBuffer(length: Long, block: (ByteBuffer) -> T): T diff --git a/kgl-core/src/commonMain/kotlin/com/kgl/core/ByteBuffer.kt b/kgl-core/src/commonMain/kotlin/com/kgl/core/ByteBuffer.kt deleted file mode 100644 index 225793c..0000000 --- a/kgl-core/src/commonMain/kotlin/com/kgl/core/ByteBuffer.kt +++ /dev/null @@ -1,21 +0,0 @@ -package com.kgl.core - -expect class ByteBuffer : Buffer { - override val size: ULong - val length: Long - - operator fun get(index: Long): Byte - operator fun set(index: Long, value: Byte) - - fun get(dst: ByteArray, srcIndex: Long = 0L, dstIndex: Long = 0L, length: Long = dst.size.toLong()) - fun set(src: ByteArray, srcIndex: Long = 0L, dstIndex: Long = 0L, length: Long = src.size.toLong()) - - fun copyTo(dst: ByteBuffer, srcIndex: Long = 0L, dstIndex: Long = 0L, length: Long = dst.length - dstIndex) - fun slice(index: Long, length: Long): ByteBuffer -} - -@Suppress("NOTHING_TO_INLINE") -internal inline fun ByteBuffer.checkBounds(index: Long, length: Long) { - require(index in 0 until this.length) - require(length in 0 until (this.length - index)) -} diff --git a/kgl-core/src/commonMain/kotlin/com/kgl/core/DirectMemory.kt b/kgl-core/src/commonMain/kotlin/com/kgl/core/DirectMemory.kt new file mode 100644 index 0000000..fcb5adf --- /dev/null +++ b/kgl-core/src/commonMain/kotlin/com/kgl/core/DirectMemory.kt @@ -0,0 +1,20 @@ +package com.kgl.core + +expect class DirectMemory { + val size: Long + + operator fun get(offset: Long): Byte + operator fun set(offset: Long, value: Byte) + + fun get(dst: ByteArray, srcOffset: Long = 0L, dstOffset: Long = 0L, length: Long = dst.size.toLong()) + fun set(src: ByteArray, srcOffset: Long = 0L, dstOffset: Long = 0L, length: Long = src.size.toLong()) + + fun copyTo(dst: DirectMemory, srcOffset: Long = 0L, dstOffset: Long = 0L, length: Long = dst.size - dstOffset) + fun slice(offset: Long, length: Long): DirectMemory +} + +@Suppress("NOTHING_TO_INLINE") +internal inline fun DirectMemory.checkBounds(offset: Long, length: Long) { + require(offset in 0 until this.size) + require(length in 0 until (this.size - offset)) +} diff --git a/kgl-core/src/commonMain/kotlin/com/kgl/core/MemUtils.kt b/kgl-core/src/commonMain/kotlin/com/kgl/core/MemUtils.kt new file mode 100644 index 0000000..66bbf4b --- /dev/null +++ b/kgl-core/src/commonMain/kotlin/com/kgl/core/MemUtils.kt @@ -0,0 +1,4 @@ +package com.kgl.core + + +expect inline fun withMemory(length: Long, block: (DirectMemory) -> T): T diff --git a/kgl-core/src/jsMain/kotlin/com/kgl/core/BufferUtils.kt b/kgl-core/src/jsMain/kotlin/com/kgl/core/BufferUtils.kt deleted file mode 100644 index b22d8c6..0000000 --- a/kgl-core/src/jsMain/kotlin/com/kgl/core/BufferUtils.kt +++ /dev/null @@ -1,8 +0,0 @@ -package com.kgl.core - -import org.khronos.webgl.Int8Array - -actual inline fun withByteBuffer(length: Long, block: (ByteBuffer) -> T): T { - val array = ByteArray(length.toInt()) - return block(ByteBuffer(array.unsafeCast())) -} diff --git a/kgl-core/src/jsMain/kotlin/com/kgl/core/ByteBuffer.kt b/kgl-core/src/jsMain/kotlin/com/kgl/core/ByteBuffer.kt deleted file mode 100644 index 6e9acd4..0000000 --- a/kgl-core/src/jsMain/kotlin/com/kgl/core/ByteBuffer.kt +++ /dev/null @@ -1,45 +0,0 @@ -package com.kgl.core - -import org.khronos.webgl.Int8Array -import org.khronos.webgl.get -import org.khronos.webgl.set - -actual class ByteBuffer(private val ptr: Int8Array) : Buffer { - actual val length: Long get() = ptr.length.toLong() - actual override val size: ULong get() = length.toULong() * Byte.SIZE_BYTES.toUInt() - - actual operator fun get(index: Long): Byte { - return ptr[index.toInt()] - } - - actual operator fun set(index: Long, value: Byte) { - ptr[index.toInt()] = value - } - - actual fun get(dst: ByteArray, srcIndex: Long, dstIndex: Long, length: Long) { - checkBounds(srcIndex, length) - for (i in 0 until length) { - dst[(dstIndex + i).toInt()] = get(srcIndex + i) - } - } - - actual fun set(src: ByteArray, srcIndex: Long, dstIndex: Long, length: Long) { - checkBounds(dstIndex, length) - for (i in 0 until length) { - this[dstIndex + i] = src[(srcIndex + i).toInt()] - } - } - - actual fun copyTo(dst: ByteBuffer, srcIndex: Long, dstIndex: Long, length: Long) { - checkBounds(srcIndex, length) - dst.checkBounds(dstIndex, length) - for (i in 0 until length) { - dst[dstIndex + i] = get(srcIndex + i) - } - } - - actual fun slice(index: Long, length: Long): ByteBuffer { - checkBounds(index, length) - return ByteBuffer(ptr.subarray(index.toInt(), (index + length).toInt())) - } -} diff --git a/kgl-core/src/jsMain/kotlin/com/kgl/core/DirectMemory.kt b/kgl-core/src/jsMain/kotlin/com/kgl/core/DirectMemory.kt new file mode 100644 index 0000000..ee7068e --- /dev/null +++ b/kgl-core/src/jsMain/kotlin/com/kgl/core/DirectMemory.kt @@ -0,0 +1,42 @@ +package com.kgl.core + +import org.khronos.webgl.DataView + +actual class DirectMemory(private val ptr: DataView) { + actual val size: Long get() = ptr.byteLength.toLong() + + actual operator fun get(offset: Long): Byte { + return ptr.getInt8(offset.toInt()) + } + + actual operator fun set(offset: Long, value: Byte) { + ptr.setInt8(offset.toInt(), value) + } + + actual fun get(dst: ByteArray, srcOffset: Long, dstOffset: Long, length: Long) { + checkBounds(srcOffset, length) + for (i in 0 until length) { + dst[(dstOffset + i).toInt()] = get(srcOffset + i) + } + } + + actual fun set(src: ByteArray, srcOffset: Long, dstOffset: Long, length: Long) { + checkBounds(dstOffset, length) + for (i in 0 until length) { + this[dstOffset + i] = src[(srcOffset + i).toInt()] + } + } + + actual fun copyTo(dst: DirectMemory, srcOffset: Long, dstOffset: Long, length: Long) { + checkBounds(srcOffset, length) + dst.checkBounds(dstOffset, length) + for (i in 0 until length) { + dst[dstOffset + i] = get(srcOffset + i) + } + } + + actual fun slice(offset: Long, length: Long): DirectMemory { + checkBounds(offset, length) + return DirectMemory(DataView(ptr.buffer, ptr.byteOffset + offset.toInt(), length.toInt())) + } +} diff --git a/kgl-core/src/jsMain/kotlin/com/kgl/core/MemUtils.kt b/kgl-core/src/jsMain/kotlin/com/kgl/core/MemUtils.kt new file mode 100644 index 0000000..cf9c801 --- /dev/null +++ b/kgl-core/src/jsMain/kotlin/com/kgl/core/MemUtils.kt @@ -0,0 +1,11 @@ +package com.kgl.core + +import org.khronos.webgl.DataView +import org.khronos.webgl.Int8Array + +actual inline fun withMemory(length: Long, block: (DirectMemory) -> T): T { + val array = ByteArray(length.toInt()) + val jsArray = array.unsafeCast() + val view = DataView(jsArray.buffer, jsArray.byteOffset, jsArray.byteLength) + return block(DirectMemory(view)) +} diff --git a/kgl-core/src/jvmMain/kotlin/com/kgl/core/ByteBuffer.kt b/kgl-core/src/jvmMain/kotlin/com/kgl/core/ByteBuffer.kt deleted file mode 100644 index 73d5d60..0000000 --- a/kgl-core/src/jvmMain/kotlin/com/kgl/core/ByteBuffer.kt +++ /dev/null @@ -1,51 +0,0 @@ -package com.kgl.core - -import org.lwjgl.system.MemoryUtil -import org.lwjgl.system.jni.JNINativeInterface -import java.nio.ByteBuffer as JvmByteBuffer - -actual class ByteBuffer(private val ptr: Long, actual val length: Long) : Buffer { - actual override val size: ULong get() = (length * Byte.SIZE_BYTES).toULong() - - constructor(buffer: JvmByteBuffer) : this(MemoryUtil.memAddress(buffer), buffer.capacity().toLong()) - - actual operator fun get(index: Long): Byte { - return MemoryUtil.memGetByte(ptr + (index * Byte.SIZE_BYTES)) - } - - actual operator fun set(index: Long, value: Byte) { - MemoryUtil.memPutByte(ptr + (index * Byte.SIZE_BYTES), value) - } - - actual fun get(dst: ByteArray, srcIndex: Long, dstIndex: Long, length: Long) { - checkBounds(srcIndex, length) - - JNINativeInterface.nSetByteArrayRegion(dst, dstIndex.toInt(), length.toInt(), ptr + (srcIndex * Byte.SIZE_BYTES)) - } - - actual fun set(src: ByteArray, srcIndex: Long, dstIndex: Long, length: Long) { - checkBounds(dstIndex, length) - JNINativeInterface.nGetByteArrayRegion(src, srcIndex.toInt(), length.toInt(), ptr + (dstIndex * Byte.SIZE_BYTES)) - } - - actual fun copyTo(dst: ByteBuffer, srcIndex: Long, dstIndex: Long, length: Long) { - checkBounds(srcIndex, length) - dst.checkBounds(dstIndex, length) - - MemoryUtil.memCopy( - ptr + (srcIndex * Byte.SIZE_BYTES), - dst.ptr + (dstIndex * Byte.SIZE_BYTES), - length - ) - } - - actual fun slice(index: Long, length: Long): ByteBuffer { - checkBounds(index, length) - - return ByteBuffer(ptr + (index * Byte.SIZE_BYTES), length) - } - - fun asJvmByteBuffer(): JvmByteBuffer { - return MemoryUtil.memByteBuffer(ptr, length.toInt()) - } -} diff --git a/kgl-core/src/jvmMain/kotlin/com/kgl/core/DirectMemory.kt b/kgl-core/src/jvmMain/kotlin/com/kgl/core/DirectMemory.kt new file mode 100644 index 0000000..ad2bb1d --- /dev/null +++ b/kgl-core/src/jvmMain/kotlin/com/kgl/core/DirectMemory.kt @@ -0,0 +1,50 @@ +package com.kgl.core + +import org.lwjgl.system.MemoryUtil +import org.lwjgl.system.jni.JNINativeInterface +import java.nio.ByteBuffer as JvmByteBuffer + +actual class DirectMemory(private val ptr: Long, actual val size: Long) { + + constructor(buffer: JvmByteBuffer) : this(MemoryUtil.memAddress(buffer), buffer.capacity().toLong()) + + actual operator fun get(offset: Long): Byte { + return MemoryUtil.memGetByte(ptr + (offset * Byte.SIZE_BYTES)) + } + + actual operator fun set(offset: Long, value: Byte) { + MemoryUtil.memPutByte(ptr + (offset * Byte.SIZE_BYTES), value) + } + + actual fun get(dst: ByteArray, srcOffset: Long, dstOffset: Long, length: Long) { + checkBounds(srcOffset, length) + + JNINativeInterface.nSetByteArrayRegion(dst, dstOffset.toInt(), length.toInt(), ptr + (srcOffset * Byte.SIZE_BYTES)) + } + + actual fun set(src: ByteArray, srcOffset: Long, dstOffset: Long, length: Long) { + checkBounds(dstOffset, length) + JNINativeInterface.nGetByteArrayRegion(src, srcOffset.toInt(), length.toInt(), ptr + (dstOffset * Byte.SIZE_BYTES)) + } + + actual fun copyTo(dst: DirectMemory, srcOffset: Long, dstOffset: Long, length: Long) { + checkBounds(srcOffset, length) + dst.checkBounds(dstOffset, length) + + MemoryUtil.memCopy( + ptr + (srcOffset * Byte.SIZE_BYTES), + dst.ptr + (dstOffset * Byte.SIZE_BYTES), + length + ) + } + + actual fun slice(offset: Long, length: Long): DirectMemory { + checkBounds(offset, length) + + return DirectMemory(ptr + (offset * Byte.SIZE_BYTES), length) + } + + fun asJvmByteBuffer(): JvmByteBuffer { + return MemoryUtil.memByteBuffer(ptr, size.toInt()) + } +} diff --git a/kgl-core/src/jvmMain/kotlin/com/kgl/core/BufferUtils.kt b/kgl-core/src/jvmMain/kotlin/com/kgl/core/MemUtils.kt similarity index 58% rename from kgl-core/src/jvmMain/kotlin/com/kgl/core/BufferUtils.kt rename to kgl-core/src/jvmMain/kotlin/com/kgl/core/MemUtils.kt index c6f66b4..f58cf2c 100644 --- a/kgl-core/src/jvmMain/kotlin/com/kgl/core/BufferUtils.kt +++ b/kgl-core/src/jvmMain/kotlin/com/kgl/core/MemUtils.kt @@ -3,10 +3,10 @@ package com.kgl.core import org.lwjgl.system.MemoryUtil -actual inline fun withByteBuffer(length: Long, block: (ByteBuffer) -> T): T { +actual inline fun withMemory(length: Long, block: (DirectMemory) -> T): T { val jvmBuffer = MemoryUtil.memAlloc(length.toInt()) try { - return block(ByteBuffer(jvmBuffer)) + return block(DirectMemory(jvmBuffer)) } finally { MemoryUtil.memFree(jvmBuffer) } diff --git a/kgl-core/src/nativeMain/kotlin/com/kgl/core/ByteBuffer.kt b/kgl-core/src/nativeMain/kotlin/com/kgl/core/ByteBuffer.kt deleted file mode 100644 index 41a7f4a..0000000 --- a/kgl-core/src/nativeMain/kotlin/com/kgl/core/ByteBuffer.kt +++ /dev/null @@ -1,49 +0,0 @@ -package com.kgl.core - -import kotlinx.cinterop.* -import platform.posix.memcpy - -actual class ByteBuffer(private val ptr: CPointer, actual val length: Long) : Buffer { - actual override val size: ULong get() = (length * Byte.SIZE_BYTES).toULong() - - actual operator fun get(index: Long): Byte { - return ptr[index] - } - - actual operator fun set(index: Long, value: Byte) { - ptr[index] = value - } - - actual fun get(dst: ByteArray, srcIndex: Long, dstIndex: Long, length: Long) { - checkBounds(srcIndex, length) - - dst.usePinned { - memcpy(it.addressOf(dstIndex.toInt()), ptr + srcIndex, length.convert()) - } - } - - actual fun set(src: ByteArray, srcIndex: Long, dstIndex: Long, length: Long) { - checkBounds(dstIndex, length) - - src.usePinned { - memcpy(ptr + dstIndex, it.addressOf(srcIndex.toInt()), length.convert()) - } - } - - actual fun copyTo(dst: ByteBuffer, srcIndex: Long, dstIndex: Long, length: Long) { - checkBounds(srcIndex, length) - dst.checkBounds(dstIndex, length) - - memcpy(dst.ptr + dstIndex, ptr + srcIndex, length.convert()) - } - - actual fun slice(index: Long, length: Long): ByteBuffer { - checkBounds(index, length) - - return ByteBuffer((ptr + index)!!, length) - } - - fun asCPointer(): CPointer { - return ptr - } -} diff --git a/kgl-core/src/nativeMain/kotlin/com/kgl/core/DirectMemory.kt b/kgl-core/src/nativeMain/kotlin/com/kgl/core/DirectMemory.kt new file mode 100644 index 0000000..90fd047 --- /dev/null +++ b/kgl-core/src/nativeMain/kotlin/com/kgl/core/DirectMemory.kt @@ -0,0 +1,48 @@ +package com.kgl.core + +import kotlinx.cinterop.* +import platform.posix.memcpy + +actual class DirectMemory(private val ptr: CPointer, actual val size: Long) { + + actual operator fun get(offset: Long): Byte { + return ptr[offset] + } + + actual operator fun set(offset: Long, value: Byte) { + ptr[offset] = value + } + + actual fun get(dst: ByteArray, srcOffset: Long, dstOffset: Long, length: Long) { + checkBounds(srcOffset, length) + + dst.usePinned { + memcpy(it.addressOf(dstOffset.toInt()), ptr + srcOffset, length.convert()) + } + } + + actual fun set(src: ByteArray, srcOffset: Long, dstOffset: Long, length: Long) { + checkBounds(dstOffset, length) + + src.usePinned { + memcpy(ptr + dstOffset, it.addressOf(srcOffset.toInt()), length.convert()) + } + } + + actual fun copyTo(dst: DirectMemory, srcOffset: Long, dstOffset: Long, length: Long) { + checkBounds(srcOffset, length) + dst.checkBounds(dstOffset, length) + + memcpy(dst.ptr + dstOffset, ptr + srcOffset, length.convert()) + } + + actual fun slice(offset: Long, length: Long): DirectMemory { + checkBounds(offset, length) + + return DirectMemory((ptr + offset)!!, length) + } + + fun asCPointer(): CPointer { + return ptr + } +} diff --git a/kgl-core/src/nativeMain/kotlin/com/kgl/core/BufferUtils.kt b/kgl-core/src/nativeMain/kotlin/com/kgl/core/MemUtils.kt similarity index 57% rename from kgl-core/src/nativeMain/kotlin/com/kgl/core/BufferUtils.kt rename to kgl-core/src/nativeMain/kotlin/com/kgl/core/MemUtils.kt index 683bfa9..f8d39db 100644 --- a/kgl-core/src/nativeMain/kotlin/com/kgl/core/BufferUtils.kt +++ b/kgl-core/src/nativeMain/kotlin/com/kgl/core/MemUtils.kt @@ -3,10 +3,10 @@ package com.kgl.core import kotlinx.cinterop.addressOf import kotlinx.cinterop.usePinned -actual inline fun withByteBuffer(length: Long, block: (ByteBuffer) -> T): T { +actual inline fun withMemory(length: Long, block: (DirectMemory) -> T): T { val array = ByteArray(length.toInt()) return array.usePinned { - val buffer = ByteBuffer(it.addressOf(0), length) + val buffer = DirectMemory(it.addressOf(0), length) block(buffer) } } diff --git a/kgl-glfw/src/commonMain/kotlin/com/kgl/glfw/Image.kt b/kgl-glfw/src/commonMain/kotlin/com/kgl/glfw/Image.kt index 319f090..1d4e030 100644 --- a/kgl-glfw/src/commonMain/kotlin/com/kgl/glfw/Image.kt +++ b/kgl-glfw/src/commonMain/kotlin/com/kgl/glfw/Image.kt @@ -15,6 +15,6 @@ */ package com.kgl.glfw -import com.kgl.core.ByteBuffer +import com.kgl.core.DirectMemory -data class Image(val pixels: ByteBuffer, val width: Int, val height: Int) +data class Image(val pixels: DirectMemory, val width: Int, val height: Int) diff --git a/kgl-stb/src/commonMain/kotlin/com/kgl/stb/STBIOCallbacks.kt b/kgl-stb/src/commonMain/kotlin/com/kgl/stb/STBIOCallbacks.kt index 797f0e2..e7f9308 100644 --- a/kgl-stb/src/commonMain/kotlin/com/kgl/stb/STBIOCallbacks.kt +++ b/kgl-stb/src/commonMain/kotlin/com/kgl/stb/STBIOCallbacks.kt @@ -1,13 +1,13 @@ package com.kgl.stb -import com.kgl.core.ByteBuffer +import com.kgl.core.DirectMemory interface STBIOCallbacks { /** * Fill 'data' with 'size' bytes. * @return number of bytes actually read */ - fun read(data: ByteBuffer): Int + fun read(data: DirectMemory): Int /** * Skip the next 'n' bytes, or 'unget' the last -n bytes if negative diff --git a/kgl-stb/src/commonMain/kotlin/com/kgl/stb/STBImage.kt b/kgl-stb/src/commonMain/kotlin/com/kgl/stb/STBImage.kt index 3d3ab83..1fe4cc0 100644 --- a/kgl-stb/src/commonMain/kotlin/com/kgl/stb/STBImage.kt +++ b/kgl-stb/src/commonMain/kotlin/com/kgl/stb/STBImage.kt @@ -15,22 +15,22 @@ */ package com.kgl.stb -import com.kgl.core.ByteBuffer +import com.kgl.core.DirectMemory import com.kgl.core.Closeable expect class STBImage : Closeable { - val buffer: ByteBuffer + val buffer: DirectMemory val info: STBInfo companion object { - fun load(buffer: ByteBuffer, desiredChannels: Channels? = null): STBImage + fun load(buffer: DirectMemory, desiredChannels: Channels? = null): STBImage fun load(callbacks: STBIOCallbacks, desiredChannels: Channels? = null): STBImage // fun loadGif(buffer: ByteBuffer, desiredChannels: Channels? = null): STBImage - fun load16(buffer: ByteBuffer, desiredChannels: Channels? = null): STBImage + fun load16(buffer: DirectMemory, desiredChannels: Channels? = null): STBImage fun load16(callbacks: STBIOCallbacks, desiredChannels: Channels? = null): STBImage - fun loadf(buffer: ByteBuffer, desiredChannels: Channels? = null): STBImage + fun loadf(buffer: DirectMemory, desiredChannels: Channels? = null): STBImage fun loadf(callbacks: STBIOCallbacks, desiredChannels: Channels? = null): STBImage fun setHdrToLdrGamma(gamma: Float) @@ -40,15 +40,15 @@ expect class STBImage : Closeable { fun setLdrToHdrScale(scale: Float) fun isHdr(callbacks: STBIOCallbacks): Boolean - fun isHdr(buffer: ByteBuffer): Boolean + fun isHdr(buffer: DirectMemory): Boolean val failureReason: String? - fun loadInfo(buffer: ByteBuffer): STBInfo + fun loadInfo(buffer: DirectMemory): STBInfo fun loadInfo(callbacks: STBIOCallbacks): STBInfo fun is16Bit(callbacks: STBIOCallbacks): Boolean - fun is16Bit(buffer: ByteBuffer): Boolean + fun is16Bit(buffer: DirectMemory): Boolean /** * For image formats that explicitly notate that they have premultiplied alpha, diff --git a/kgl-stb/src/jvmMain/kotlin/com/kgl/stb/STBImage.kt b/kgl-stb/src/jvmMain/kotlin/com/kgl/stb/STBImage.kt index 8c64244..6e90ce5 100644 --- a/kgl-stb/src/jvmMain/kotlin/com/kgl/stb/STBImage.kt +++ b/kgl-stb/src/jvmMain/kotlin/com/kgl/stb/STBImage.kt @@ -16,7 +16,7 @@ package com.kgl.stb import com.kgl.core.Closeable -import com.kgl.core.ByteBuffer +import com.kgl.core.DirectMemory import org.lwjgl.stb.STBIIOCallbacks import org.lwjgl.stb.STBImage.* import org.lwjgl.system.MemoryStack @@ -26,7 +26,7 @@ import java.nio.ByteBuffer as JvmByteBuffer import java.nio.IntBuffer actual class STBImage( - actual val buffer: ByteBuffer, + actual val buffer: DirectMemory, actual val info: STBInfo) : Closeable { override fun close() { @@ -35,7 +35,7 @@ actual class STBImage( actual companion object { private inline fun genericLoad( - buffer: ByteBuffer, desiredChannels: Channels?, + buffer: DirectMemory, desiredChannels: Channels?, crossinline block: ( buffer: JvmByteBuffer, x: IntBuffer, @@ -56,7 +56,7 @@ actual class STBImage( val bytes = convert(result ?: throw STBException(failureReason)) return STBImage( - ByteBuffer(bytes), + DirectMemory(bytes), STBInfo(x[0], y[0], Channels.values()[channels[0] - 1]) ) } finally { @@ -66,7 +66,7 @@ actual class STBImage( private inline fun usingNativeCallbacks(callbacks: STBIOCallbacks, block: (STBIIOCallbacks, Long) -> T): T { val nativeCallbacks = STBIIOCallbacks.mallocStack() - nativeCallbacks.read { _, data, size -> callbacks.read(com.kgl.core.ByteBuffer(MemoryUtil.memByteBuffer(data, size))) } + nativeCallbacks.read { _, data, size -> callbacks.read(com.kgl.core.DirectMemory(MemoryUtil.memByteBuffer(data, size))) } nativeCallbacks.skip { _, n -> callbacks.skip(n) } nativeCallbacks.eof { if (callbacks.eof) 1 else 0 } try { @@ -102,7 +102,7 @@ actual class STBImage( val bytes = convert(result ?: throw STBException(failureReason)) STBImage( - ByteBuffer(bytes), + DirectMemory(bytes), STBInfo(x[0], y[0], Channels.values()[channels[0] - 1]) ) } @@ -111,14 +111,14 @@ actual class STBImage( } } - actual fun load(buffer: ByteBuffer, desiredChannels: Channels?): STBImage { + actual fun load(buffer: DirectMemory, desiredChannels: Channels?): STBImage { return genericLoad(buffer, desiredChannels, ::stbi_load_from_memory) { it } } actual fun load(callbacks: STBIOCallbacks, desiredChannels: Channels?): STBImage { return genericLoad(callbacks, desiredChannels, ::stbi_load_from_callbacks) { it } } - actual fun load16(buffer: ByteBuffer, desiredChannels: Channels?): STBImage { + actual fun load16(buffer: DirectMemory, desiredChannels: Channels?): STBImage { return genericLoad(buffer, desiredChannels, ::stbi_load_16_from_memory) { MemoryUtil.memByteBuffer(MemoryUtil.memAddress(it), it.capacity() * Short.SIZE_BYTES) } @@ -129,7 +129,7 @@ actual class STBImage( } } - actual fun loadf(buffer: ByteBuffer, desiredChannels: Channels?): STBImage { + actual fun loadf(buffer: DirectMemory, desiredChannels: Channels?): STBImage { return genericLoad(buffer, desiredChannels, ::stbi_loadf_from_memory) { MemoryUtil.memByteBuffer(MemoryUtil.memAddress(it), it.capacity() * Int.SIZE_BYTES) } @@ -162,13 +162,13 @@ actual class STBImage( MemoryStack.stackPop() } } - actual fun isHdr(buffer: ByteBuffer): Boolean { + actual fun isHdr(buffer: DirectMemory): Boolean { return stbi_is_hdr_from_memory(buffer.asJvmByteBuffer()) } actual val failureReason: String? get() = stbi_failure_reason() - actual fun loadInfo(buffer: ByteBuffer): STBInfo { + actual fun loadInfo(buffer: DirectMemory): STBInfo { MemoryStack.stackPush() try { val x = MemoryStack.stackMallocInt(1) @@ -215,7 +215,7 @@ actual class STBImage( MemoryStack.stackPop() } } - actual fun is16Bit(buffer: ByteBuffer): Boolean { + actual fun is16Bit(buffer: DirectMemory): Boolean { return stbi_is_16_bit_from_memory(buffer.asJvmByteBuffer()) } diff --git a/kgl-stb/src/nativeMain/kotlin/com/kgl/stb/STBImage.kt b/kgl-stb/src/nativeMain/kotlin/com/kgl/stb/STBImage.kt index 6cc6c37..2aee9da 100644 --- a/kgl-stb/src/nativeMain/kotlin/com/kgl/stb/STBImage.kt +++ b/kgl-stb/src/nativeMain/kotlin/com/kgl/stb/STBImage.kt @@ -15,14 +15,14 @@ */ package com.kgl.stb -import com.kgl.core.ByteBuffer +import com.kgl.core.DirectMemory import com.kgl.core.Closeable import com.kgl.core.VirtualStack import cstb.* import kotlinx.cinterop.* actual class STBImage( - actual val buffer: ByteBuffer, + actual val buffer: DirectMemory, actual val info: STBInfo) : Closeable { override fun close() { @@ -35,7 +35,7 @@ actual class STBImage( private val nativeCallbacks = cValue { read = staticCFunction { user, data, size -> val callbacks = user!!.asStableRef().get() - callbacks.read(ByteBuffer(data!!, size.convert())) + callbacks.read(DirectMemory(data!!, size.convert())) } skip = staticCFunction { user, n -> val callbacks = user!!.asStableRef().get() @@ -49,7 +49,7 @@ actual class STBImage( private val Channels?.asStbChannels: Int get() = this?.value ?: STBI_default.toInt() private inline fun genericLoad( - buffer: ByteBuffer, desiredChannels: Channels?, + buffer: DirectMemory, desiredChannels: Channels?, crossinline block: ( buffer: CValuesRef?, len: Int, @@ -71,7 +71,7 @@ actual class STBImage( val bytes = (result ?: throw STBException(failureReason)).reinterpret() return STBImage( - ByteBuffer(bytes, x.value * y.value * channels.value * sizeOf()), + DirectMemory(bytes, x.value * y.value * channels.value * sizeOf()), STBInfo(x.value, y.value, Channels.values()[channels.value - 1]) ) } finally { @@ -106,7 +106,7 @@ actual class STBImage( val bytes = (result ?: throw STBException(failureReason)).reinterpret() return STBImage( - ByteBuffer(bytes, x.value * y.value * channels.value * sizeOf()), + DirectMemory(bytes, x.value * y.value * channels.value * sizeOf()), STBInfo(x.value, y.value, Channels.values()[channels.value - 1]) ) } finally { @@ -115,21 +115,21 @@ actual class STBImage( } } - actual fun load(buffer: ByteBuffer, desiredChannels: Channels?): STBImage { + actual fun load(buffer: DirectMemory, desiredChannels: Channels?): STBImage { return genericLoad(buffer, desiredChannels, ::stbi_load_from_memory) } actual fun load(callbacks: STBIOCallbacks, desiredChannels: Channels?): STBImage { return genericLoad(callbacks, desiredChannels, ::stbi_load_from_callbacks) } - actual fun load16(buffer: ByteBuffer, desiredChannels: Channels?): STBImage { + actual fun load16(buffer: DirectMemory, desiredChannels: Channels?): STBImage { return genericLoad(buffer, desiredChannels, ::stbi_load_16_from_memory) } actual fun load16(callbacks: STBIOCallbacks, desiredChannels: Channels?): STBImage { return genericLoad(callbacks, desiredChannels, ::stbi_load_16_from_callbacks) } - actual fun loadf(buffer: ByteBuffer, desiredChannels: Channels?): STBImage { + actual fun loadf(buffer: DirectMemory, desiredChannels: Channels?): STBImage { return genericLoad(buffer, desiredChannels, ::stbi_loadf_from_memory) } actual fun loadf(callbacks: STBIOCallbacks, desiredChannels: Channels?): STBImage { @@ -159,14 +159,14 @@ actual class STBImage( userData.dispose() } } - actual fun isHdr(buffer: ByteBuffer): Boolean { + actual fun isHdr(buffer: DirectMemory): Boolean { val result= stbi_is_hdr_from_memory(buffer.asCPointer().reinterpret(), buffer.size.toInt()) return result != 0 } actual val failureReason: String? get() = stbi_failure_reason()?.toKStringFromUtf8() - actual fun loadInfo(buffer: ByteBuffer): STBInfo { + actual fun loadInfo(buffer: DirectMemory): STBInfo { VirtualStack.push() try { val x = VirtualStack.alloc() @@ -218,7 +218,7 @@ actual class STBImage( userData.dispose() } } - actual fun is16Bit(buffer: ByteBuffer): Boolean { + actual fun is16Bit(buffer: DirectMemory): Boolean { val result = stbi_is_16_bit_from_memory(buffer.asCPointer().reinterpret(), buffer.size.toInt()) return result != 0 } diff --git a/kgl-vulkan/src/commonMain/kotlin/com/kgl/vulkan/handles/AccelerationStructureNV.kt b/kgl-vulkan/src/commonMain/kotlin/com/kgl/vulkan/handles/AccelerationStructureNV.kt index 3584e1d..bea41fc 100644 --- a/kgl-vulkan/src/commonMain/kotlin/com/kgl/vulkan/handles/AccelerationStructureNV.kt +++ b/kgl-vulkan/src/commonMain/kotlin/com/kgl/vulkan/handles/AccelerationStructureNV.kt @@ -15,7 +15,7 @@ */ package com.kgl.vulkan.handles -import com.kgl.core.ByteBuffer +import com.kgl.core.DirectMemory import com.kgl.vulkan.dsls.AccelerationStructureMemoryRequirementsInfoNVBuilder import com.kgl.vulkan.enums.AccelerationStructureMemoryRequirementsTypeNV import com.kgl.vulkan.structs.MemoryRequirements2 @@ -24,7 +24,7 @@ import com.kgl.vulkan.utils.VkHandle expect class AccelerationStructureNV : VkHandle { val device: Device - fun getHandle(pData: ByteBuffer) + fun getHandle(pData: DirectMemory) fun getMemoryRequirements(type: AccelerationStructureMemoryRequirementsTypeNV, block: AccelerationStructureMemoryRequirementsInfoNVBuilder.() -> Unit = {}): MemoryRequirements2 } diff --git a/kgl-vulkan/src/commonMain/kotlin/com/kgl/vulkan/handles/CommandBuffer.kt b/kgl-vulkan/src/commonMain/kotlin/com/kgl/vulkan/handles/CommandBuffer.kt index 64caefc..a2292e5 100644 --- a/kgl-vulkan/src/commonMain/kotlin/com/kgl/vulkan/handles/CommandBuffer.kt +++ b/kgl-vulkan/src/commonMain/kotlin/com/kgl/vulkan/handles/CommandBuffer.kt @@ -15,7 +15,7 @@ */ package com.kgl.vulkan.handles -import com.kgl.core.ByteBuffer +import com.kgl.core.DirectMemory import com.kgl.vulkan.dsls.* import com.kgl.vulkan.enums.* import com.kgl.vulkan.utils.VkFlag @@ -97,7 +97,7 @@ expect class CommandBuffer : VkHandle { fun copyImageToBuffer(srcImage: Image, srcImageLayout: ImageLayout, dstBuffer: Buffer, block: BufferImageCopysBuilder.() -> Unit) - fun updateBuffer(dstBuffer: Buffer, dstOffset: ULong, data: ByteBuffer) + fun updateBuffer(dstBuffer: Buffer, dstOffset: ULong, data: DirectMemory) fun fillBuffer(dstBuffer: Buffer, dstOffset: ULong, size: ULong, data: UInt) @@ -148,7 +148,7 @@ expect class CommandBuffer : VkHandle { layout: PipelineLayout, stageFlags: VkFlag, offset: UInt, - values: ByteBuffer + values: DirectMemory ) fun beginRenderPass( @@ -225,7 +225,7 @@ expect class CommandBuffer : VkHandle { descriptorUpdateTemplate: DescriptorUpdateTemplate, layout: PipelineLayout, set: UInt, - data: ByteBuffer + data: DirectMemory ) fun setViewportWScalingNV(firstViewport: UInt, block: ViewportWScalingNVsBuilder.() -> Unit) @@ -262,7 +262,7 @@ expect class CommandBuffer : VkHandle { stride: UInt ) - fun setCheckpointNV(pCheckpointMarker: ByteBuffer) + fun setCheckpointNV(pCheckpointMarker: DirectMemory) fun bindTransformFeedbackBuffersEXT( firstBinding: UInt, diff --git a/kgl-vulkan/src/commonMain/kotlin/com/kgl/vulkan/handles/DescriptorSet.kt b/kgl-vulkan/src/commonMain/kotlin/com/kgl/vulkan/handles/DescriptorSet.kt index 0bfe4d3..7ce1294 100644 --- a/kgl-vulkan/src/commonMain/kotlin/com/kgl/vulkan/handles/DescriptorSet.kt +++ b/kgl-vulkan/src/commonMain/kotlin/com/kgl/vulkan/handles/DescriptorSet.kt @@ -15,12 +15,12 @@ */ package com.kgl.vulkan.handles -import com.kgl.core.ByteBuffer +import com.kgl.core.DirectMemory import com.kgl.vulkan.utils.VkHandle expect class DescriptorSet : VkHandle { val descriptorPool: DescriptorPool - fun updateWithTemplate(descriptorUpdateTemplate: DescriptorUpdateTemplate, data: ByteBuffer) + fun updateWithTemplate(descriptorUpdateTemplate: DescriptorUpdateTemplate, data: DirectMemory) } diff --git a/kgl-vulkan/src/commonMain/kotlin/com/kgl/vulkan/handles/Device.kt b/kgl-vulkan/src/commonMain/kotlin/com/kgl/vulkan/handles/Device.kt index 5895f32..65336ee 100644 --- a/kgl-vulkan/src/commonMain/kotlin/com/kgl/vulkan/handles/Device.kt +++ b/kgl-vulkan/src/commonMain/kotlin/com/kgl/vulkan/handles/Device.kt @@ -15,7 +15,7 @@ */ package com.kgl.vulkan.handles -import com.kgl.core.ByteBuffer +import com.kgl.core.DirectMemory import com.kgl.vulkan.dsls.* import com.kgl.vulkan.enums.* import com.kgl.vulkan.structs.DescriptorSetLayoutSupport @@ -60,7 +60,7 @@ expect class Device : VkHandle { fun createShaderModule(code: UByteArray, block: ShaderModuleCreateInfoBuilder.() -> Unit = {}): ShaderModule - fun createPipelineCache(initialData: ByteBuffer? = null, block: PipelineCacheCreateInfoBuilder.() -> Unit = {}): PipelineCache + fun createPipelineCache(initialData: DirectMemory? = null, block: PipelineCacheCreateInfoBuilder.() -> Unit = {}): PipelineCache fun createPipelineLayout(setLayouts: Collection? = null, block: PipelineLayoutCreateInfoBuilder.() -> Unit = {}): PipelineLayout @@ -93,7 +93,7 @@ expect class Device : VkHandle { fun debugMarkerSetObjectNameEXT(block: DebugMarkerObjectNameInfoEXTBuilder.() -> Unit = {}) - fun debugMarkerSetObjectTagEXT(tag: ByteBuffer, block: DebugMarkerObjectTagInfoEXTBuilder.() -> Unit = {}) + fun debugMarkerSetObjectTagEXT(tag: DirectMemory, block: DebugMarkerObjectTagInfoEXTBuilder.() -> Unit = {}) fun createIndirectCommandsLayoutNVX(block: IndirectCommandsLayoutCreateInfoNVXBuilder.() -> Unit): IndirectCommandsLayoutNVX @@ -126,13 +126,13 @@ expect class Device : VkHandle { fun getQueue2(block: DeviceQueueInfo2Builder.() -> Unit = {}): Queue - fun createValidationCacheEXT(initialData: ByteBuffer?, block: ValidationCacheCreateInfoEXTBuilder.() -> Unit = {}): ValidationCacheEXT + fun createValidationCacheEXT(initialData: DirectMemory?, block: ValidationCacheCreateInfoEXTBuilder.() -> Unit = {}): ValidationCacheEXT fun getDescriptorSetLayoutSupport(block: DescriptorSetLayoutCreateInfoBuilder.() -> Unit): DescriptorSetLayoutSupport fun setDebugUtilsObjectNameEXT(block: DebugUtilsObjectNameInfoEXTBuilder.() -> Unit = {}) - fun setDebugUtilsObjectTagEXT(tag: ByteBuffer, block: DebugUtilsObjectTagInfoEXTBuilder.() -> Unit = {}) + fun setDebugUtilsObjectTagEXT(tag: DirectMemory, block: DebugUtilsObjectTagInfoEXTBuilder.() -> Unit = {}) fun getMemoryHostPointerPropertiesEXT(handleType: ExternalMemoryHandleType, pHostPointer: Long): MemoryHostPointerPropertiesEXT diff --git a/kgl-vulkan/src/commonMain/kotlin/com/kgl/vulkan/handles/DeviceMemory.kt b/kgl-vulkan/src/commonMain/kotlin/com/kgl/vulkan/handles/DeviceMemory.kt index 5a5376b..deee5eb 100644 --- a/kgl-vulkan/src/commonMain/kotlin/com/kgl/vulkan/handles/DeviceMemory.kt +++ b/kgl-vulkan/src/commonMain/kotlin/com/kgl/vulkan/handles/DeviceMemory.kt @@ -15,7 +15,7 @@ */ package com.kgl.vulkan.handles -import com.kgl.core.ByteBuffer +import com.kgl.core.DirectMemory import com.kgl.vulkan.dsls.MemoryGetFdInfoKHRBuilder import com.kgl.vulkan.utils.VkHandle @@ -26,7 +26,7 @@ expect class DeviceMemory : VkHandle { val commitment: ULong - fun map(offset: ULong, size: ULong): ByteBuffer + fun map(offset: ULong, size: ULong): DirectMemory fun unmap() diff --git a/kgl-vulkan/src/commonMain/kotlin/com/kgl/vulkan/handles/Pipeline.kt b/kgl-vulkan/src/commonMain/kotlin/com/kgl/vulkan/handles/Pipeline.kt index e08d96e..6612811 100644 --- a/kgl-vulkan/src/commonMain/kotlin/com/kgl/vulkan/handles/Pipeline.kt +++ b/kgl-vulkan/src/commonMain/kotlin/com/kgl/vulkan/handles/Pipeline.kt @@ -15,7 +15,7 @@ */ package com.kgl.vulkan.handles -import com.kgl.core.ByteBuffer +import com.kgl.core.DirectMemory import com.kgl.vulkan.enums.ShaderInfoTypeAMD import com.kgl.vulkan.enums.ShaderStage import com.kgl.vulkan.utils.VkHandle @@ -26,7 +26,7 @@ expect class Pipeline : VkHandle { fun getShaderInfoAMD( shaderStage: ShaderStage, infoType: ShaderInfoTypeAMD, - info: ByteBuffer? + info: DirectMemory? ) fun compileDeferredNV(shader: UInt) @@ -34,7 +34,7 @@ expect class Pipeline : VkHandle { fun getRayTracingShaderGroupHandlesNV( firstGroup: UInt, groupCount: UInt, - data: ByteBuffer + data: DirectMemory ) } diff --git a/kgl-vulkan/src/commonMain/kotlin/com/kgl/vulkan/handles/PipelineCache.kt b/kgl-vulkan/src/commonMain/kotlin/com/kgl/vulkan/handles/PipelineCache.kt index 149e488..d4d1fe8 100644 --- a/kgl-vulkan/src/commonMain/kotlin/com/kgl/vulkan/handles/PipelineCache.kt +++ b/kgl-vulkan/src/commonMain/kotlin/com/kgl/vulkan/handles/PipelineCache.kt @@ -15,7 +15,7 @@ */ package com.kgl.vulkan.handles -import com.kgl.core.ByteBuffer +import com.kgl.core.DirectMemory import com.kgl.vulkan.utils.VkHandle expect class PipelineCache : VkHandle { @@ -23,7 +23,7 @@ expect class PipelineCache : VkHandle { val dataSize: ULong - fun getData(data: ByteBuffer): Boolean + fun getData(data: DirectMemory): Boolean fun merge(srcCaches: Collection) } diff --git a/kgl-vulkan/src/commonMain/kotlin/com/kgl/vulkan/handles/QueryPool.kt b/kgl-vulkan/src/commonMain/kotlin/com/kgl/vulkan/handles/QueryPool.kt index 0e5857e..011686b 100644 --- a/kgl-vulkan/src/commonMain/kotlin/com/kgl/vulkan/handles/QueryPool.kt +++ b/kgl-vulkan/src/commonMain/kotlin/com/kgl/vulkan/handles/QueryPool.kt @@ -15,7 +15,7 @@ */ package com.kgl.vulkan.handles -import com.kgl.core.ByteBuffer +import com.kgl.core.DirectMemory import com.kgl.vulkan.enums.QueryResult import com.kgl.vulkan.utils.VkFlag import com.kgl.vulkan.utils.VkHandle @@ -26,7 +26,7 @@ expect class QueryPool : VkHandle { fun getResults( firstQuery: UInt, queryCount: UInt, - data: ByteBuffer, + data: DirectMemory, stride: ULong, flags: VkFlag? ): Boolean diff --git a/kgl-vulkan/src/commonMain/kotlin/com/kgl/vulkan/handles/ValidationCacheEXT.kt b/kgl-vulkan/src/commonMain/kotlin/com/kgl/vulkan/handles/ValidationCacheEXT.kt index b333ac5..0911802 100644 --- a/kgl-vulkan/src/commonMain/kotlin/com/kgl/vulkan/handles/ValidationCacheEXT.kt +++ b/kgl-vulkan/src/commonMain/kotlin/com/kgl/vulkan/handles/ValidationCacheEXT.kt @@ -15,13 +15,13 @@ */ package com.kgl.vulkan.handles -import com.kgl.core.ByteBuffer +import com.kgl.core.DirectMemory import com.kgl.vulkan.utils.VkHandle expect class ValidationCacheEXT : VkHandle { val device: Device - fun getData(data: ByteBuffer?) + fun getData(data: DirectMemory?) fun merge(srcCaches: Collection) } diff --git a/kgl-vulkan/src/jvmMain/kotlin/com/kgl/vulkan/handles/AccelerationStructureNV.kt b/kgl-vulkan/src/jvmMain/kotlin/com/kgl/vulkan/handles/AccelerationStructureNV.kt index 11b2a3f..d9eb190 100644 --- a/kgl-vulkan/src/jvmMain/kotlin/com/kgl/vulkan/handles/AccelerationStructureNV.kt +++ b/kgl-vulkan/src/jvmMain/kotlin/com/kgl/vulkan/handles/AccelerationStructureNV.kt @@ -15,7 +15,7 @@ */ package com.kgl.vulkan.handles -import com.kgl.core.ByteBuffer +import com.kgl.core.DirectMemory import com.kgl.vulkan.dsls.AccelerationStructureMemoryRequirementsInfoNVBuilder import com.kgl.vulkan.enums.AccelerationStructureMemoryRequirementsTypeNV import com.kgl.vulkan.structs.MemoryRequirements2 @@ -43,7 +43,7 @@ actual class AccelerationStructureNV(override val ptr: Long, actual val device: } } - actual fun getHandle(pData: ByteBuffer) { + actual fun getHandle(pData: DirectMemory) { val accelerationStructure = this val device = accelerationStructure.device MemoryStack.stackPush() diff --git a/kgl-vulkan/src/jvmMain/kotlin/com/kgl/vulkan/handles/CommandBuffer.kt b/kgl-vulkan/src/jvmMain/kotlin/com/kgl/vulkan/handles/CommandBuffer.kt index 4207a73..795ca79 100644 --- a/kgl-vulkan/src/jvmMain/kotlin/com/kgl/vulkan/handles/CommandBuffer.kt +++ b/kgl-vulkan/src/jvmMain/kotlin/com/kgl/vulkan/handles/CommandBuffer.kt @@ -15,7 +15,7 @@ */ package com.kgl.vulkan.handles -import com.kgl.core.ByteBuffer +import com.kgl.core.DirectMemory import com.kgl.vulkan.dsls.* import com.kgl.vulkan.enums.* import com.kgl.vulkan.utils.* @@ -405,7 +405,7 @@ actual class CommandBuffer(override val ptr: VkCommandBuffer, actual val command } } - actual fun updateBuffer(dstBuffer: Buffer, dstOffset: ULong, data: ByteBuffer) { + actual fun updateBuffer(dstBuffer: Buffer, dstOffset: ULong, data: DirectMemory) { val commandBuffer = this MemoryStack.stackPush() try { @@ -596,7 +596,7 @@ actual class CommandBuffer(override val ptr: VkCommandBuffer, actual val command layout: PipelineLayout, stageFlags: VkFlag, offset: UInt, - values: ByteBuffer + values: DirectMemory ) { val commandBuffer = this MemoryStack.stackPush() @@ -824,7 +824,7 @@ actual class CommandBuffer(override val ptr: VkCommandBuffer, actual val command descriptorUpdateTemplate: DescriptorUpdateTemplate, layout: PipelineLayout, set: UInt, - data: ByteBuffer + data: DirectMemory ) { TODO() val commandBuffer = this @@ -979,7 +979,7 @@ actual class CommandBuffer(override val ptr: VkCommandBuffer, actual val command } } - actual fun setCheckpointNV(pCheckpointMarker: ByteBuffer) { + actual fun setCheckpointNV(pCheckpointMarker: DirectMemory) { TODO() val commandBuffer = this MemoryStack.stackPush() diff --git a/kgl-vulkan/src/jvmMain/kotlin/com/kgl/vulkan/handles/DescriptorSet.kt b/kgl-vulkan/src/jvmMain/kotlin/com/kgl/vulkan/handles/DescriptorSet.kt index 37628b7..0759a51 100644 --- a/kgl-vulkan/src/jvmMain/kotlin/com/kgl/vulkan/handles/DescriptorSet.kt +++ b/kgl-vulkan/src/jvmMain/kotlin/com/kgl/vulkan/handles/DescriptorSet.kt @@ -15,7 +15,7 @@ */ package com.kgl.vulkan.handles -import com.kgl.core.ByteBuffer +import com.kgl.core.DirectMemory import com.kgl.vulkan.utils.VkHandle import com.kgl.vulkan.utils.VkHandleJVM import com.kgl.vulkan.utils.toVkType @@ -28,7 +28,7 @@ actual class DescriptorSet(override val ptr: Long, actual val descriptorPool: De vkFreeDescriptorSets(descriptorPool.device.ptr, descriptorPool.ptr, ptr) } - actual fun updateWithTemplate(descriptorUpdateTemplate: DescriptorUpdateTemplate, data: ByteBuffer) { + actual fun updateWithTemplate(descriptorUpdateTemplate: DescriptorUpdateTemplate, data: DirectMemory) { TODO() MemoryStack.stackPush() try { diff --git a/kgl-vulkan/src/jvmMain/kotlin/com/kgl/vulkan/handles/Device.kt b/kgl-vulkan/src/jvmMain/kotlin/com/kgl/vulkan/handles/Device.kt index 308e212..ebda666 100644 --- a/kgl-vulkan/src/jvmMain/kotlin/com/kgl/vulkan/handles/Device.kt +++ b/kgl-vulkan/src/jvmMain/kotlin/com/kgl/vulkan/handles/Device.kt @@ -15,7 +15,7 @@ */ package com.kgl.vulkan.handles -import com.kgl.core.ByteBuffer +import com.kgl.core.DirectMemory import com.kgl.vulkan.dsls.* import com.kgl.vulkan.enums.* import com.kgl.vulkan.structs.* @@ -291,7 +291,7 @@ actual class Device(override val ptr: VkDevice, actual val physicalDevice: Physi } } - actual fun createPipelineCache(initialData: ByteBuffer?, block: PipelineCacheCreateInfoBuilder.() -> Unit): PipelineCache { + actual fun createPipelineCache(initialData: DirectMemory?, block: PipelineCacheCreateInfoBuilder.() -> Unit): PipelineCache { val device = this MemoryStack.stackPush() try { @@ -543,7 +543,7 @@ actual class Device(override val ptr: VkDevice, actual val physicalDevice: Physi } } - actual fun debugMarkerSetObjectTagEXT(tag: ByteBuffer, block: DebugMarkerObjectTagInfoEXTBuilder.() -> Unit) { + actual fun debugMarkerSetObjectTagEXT(tag: DirectMemory, block: DebugMarkerObjectTagInfoEXTBuilder.() -> Unit) { val device = this MemoryStack.stackPush() try { @@ -760,7 +760,7 @@ actual class Device(override val ptr: VkDevice, actual val physicalDevice: Physi } } - actual fun createValidationCacheEXT(initialData: ByteBuffer?, block: ValidationCacheCreateInfoEXTBuilder.() -> Unit): ValidationCacheEXT { + actual fun createValidationCacheEXT(initialData: DirectMemory?, block: ValidationCacheCreateInfoEXTBuilder.() -> Unit): ValidationCacheEXT { val device = this MemoryStack.stackPush() try { @@ -808,7 +808,7 @@ actual class Device(override val ptr: VkDevice, actual val physicalDevice: Physi } } - actual fun setDebugUtilsObjectTagEXT(tag: ByteBuffer, block: DebugUtilsObjectTagInfoEXTBuilder.() -> Unit) { + actual fun setDebugUtilsObjectTagEXT(tag: DirectMemory, block: DebugUtilsObjectTagInfoEXTBuilder.() -> Unit) { val device = this MemoryStack.stackPush() try { diff --git a/kgl-vulkan/src/jvmMain/kotlin/com/kgl/vulkan/handles/DeviceMemory.kt b/kgl-vulkan/src/jvmMain/kotlin/com/kgl/vulkan/handles/DeviceMemory.kt index 47f694a..ec95736 100644 --- a/kgl-vulkan/src/jvmMain/kotlin/com/kgl/vulkan/handles/DeviceMemory.kt +++ b/kgl-vulkan/src/jvmMain/kotlin/com/kgl/vulkan/handles/DeviceMemory.kt @@ -15,7 +15,7 @@ */ package com.kgl.vulkan.handles -import com.kgl.core.ByteBuffer +import com.kgl.core.DirectMemory import com.kgl.vulkan.dsls.MemoryGetFdInfoKHRBuilder import com.kgl.vulkan.utils.VkHandle import com.kgl.vulkan.utils.VkHandleJVM @@ -56,7 +56,7 @@ actual class DeviceMemory(override val ptr: Long, } } - actual fun map(offset: ULong, size: ULong): ByteBuffer { + actual fun map(offset: ULong, size: ULong): DirectMemory { val memory = this val device = memory.device MemoryStack.stackPush() @@ -65,7 +65,7 @@ actual class DeviceMemory(override val ptr: Long, val result = vkMapMemory(device.toVkType(), memory.toVkType(), offset.toVkType(), size.toVkType(), 0U.toVkType(), outputPtr) if (result != VK_SUCCESS) handleVkResult(result) - return ByteBuffer(outputPtr.getByteBuffer(size.toInt())) + return DirectMemory(outputPtr.getByteBuffer(size.toInt())) } finally { MemoryStack.stackPop() } diff --git a/kgl-vulkan/src/jvmMain/kotlin/com/kgl/vulkan/handles/Pipeline.kt b/kgl-vulkan/src/jvmMain/kotlin/com/kgl/vulkan/handles/Pipeline.kt index 54c51fb..9be6362 100644 --- a/kgl-vulkan/src/jvmMain/kotlin/com/kgl/vulkan/handles/Pipeline.kt +++ b/kgl-vulkan/src/jvmMain/kotlin/com/kgl/vulkan/handles/Pipeline.kt @@ -15,7 +15,7 @@ */ package com.kgl.vulkan.handles -import com.kgl.core.ByteBuffer +import com.kgl.core.DirectMemory import com.kgl.vulkan.enums.ShaderInfoTypeAMD import com.kgl.vulkan.enums.ShaderStage import com.kgl.vulkan.utils.VkHandle @@ -43,7 +43,7 @@ actual class Pipeline(override val ptr: Long, actual val device: Device) : VkHan actual fun getShaderInfoAMD( shaderStage: ShaderStage, infoType: ShaderInfoTypeAMD, - info: ByteBuffer? + info: DirectMemory? ) { TODO() val pipeline = this @@ -75,7 +75,7 @@ actual class Pipeline(override val ptr: Long, actual val device: Device) : VkHan } } - actual fun getRayTracingShaderGroupHandlesNV(firstGroup: UInt, groupCount: UInt, data: ByteBuffer) { + actual fun getRayTracingShaderGroupHandlesNV(firstGroup: UInt, groupCount: UInt, data: DirectMemory) { val pipeline = this val device = pipeline.device MemoryStack.stackPush() diff --git a/kgl-vulkan/src/jvmMain/kotlin/com/kgl/vulkan/handles/PipelineCache.kt b/kgl-vulkan/src/jvmMain/kotlin/com/kgl/vulkan/handles/PipelineCache.kt index 30d8134..e1c8f00 100644 --- a/kgl-vulkan/src/jvmMain/kotlin/com/kgl/vulkan/handles/PipelineCache.kt +++ b/kgl-vulkan/src/jvmMain/kotlin/com/kgl/vulkan/handles/PipelineCache.kt @@ -15,7 +15,7 @@ */ package com.kgl.vulkan.handles -import com.kgl.core.ByteBuffer +import com.kgl.core.DirectMemory import com.kgl.vulkan.utils.VkHandle import com.kgl.vulkan.utils.VkHandleJVM import com.kgl.vulkan.utils.handleVkResult @@ -54,7 +54,7 @@ actual class PipelineCache(override val ptr: Long, actual val device: Device) : } } - actual fun getData(data: ByteBuffer): Boolean { + actual fun getData(data: DirectMemory): Boolean { val pipelineCache = this val device = pipelineCache.device MemoryStack.stackPush() diff --git a/kgl-vulkan/src/jvmMain/kotlin/com/kgl/vulkan/handles/QueryPool.kt b/kgl-vulkan/src/jvmMain/kotlin/com/kgl/vulkan/handles/QueryPool.kt index 304d730..181b285 100644 --- a/kgl-vulkan/src/jvmMain/kotlin/com/kgl/vulkan/handles/QueryPool.kt +++ b/kgl-vulkan/src/jvmMain/kotlin/com/kgl/vulkan/handles/QueryPool.kt @@ -15,7 +15,7 @@ */ package com.kgl.vulkan.handles -import com.kgl.core.ByteBuffer +import com.kgl.core.DirectMemory import com.kgl.vulkan.enums.QueryResult import com.kgl.vulkan.utils.* import org.lwjgl.system.MemoryStack @@ -36,7 +36,7 @@ actual class QueryPool(override val ptr: Long, actual val device: Device) : VkHa actual fun getResults( firstQuery: UInt, queryCount: UInt, - data: ByteBuffer, + data: DirectMemory, stride: ULong, flags: VkFlag? ): Boolean { diff --git a/kgl-vulkan/src/jvmMain/kotlin/com/kgl/vulkan/handles/ValidationCacheEXT.kt b/kgl-vulkan/src/jvmMain/kotlin/com/kgl/vulkan/handles/ValidationCacheEXT.kt index 0d97c57..f4576fb 100644 --- a/kgl-vulkan/src/jvmMain/kotlin/com/kgl/vulkan/handles/ValidationCacheEXT.kt +++ b/kgl-vulkan/src/jvmMain/kotlin/com/kgl/vulkan/handles/ValidationCacheEXT.kt @@ -15,7 +15,7 @@ */ package com.kgl.vulkan.handles -import com.kgl.core.ByteBuffer +import com.kgl.core.DirectMemory import com.kgl.vulkan.utils.VkHandle import com.kgl.vulkan.utils.VkHandleJVM import com.kgl.vulkan.utils.handleVkResult @@ -37,7 +37,7 @@ actual class ValidationCacheEXT(override val ptr: Long, actual val device: Devic } } - actual fun getData(data: ByteBuffer?) { + actual fun getData(data: DirectMemory?) { TODO() val validationCache = this val device = validationCache.device diff --git a/kgl-vulkan/src/nativeMain/kotlin/com/kgl/vulkan/handles/AccelerationStructureNV.kt b/kgl-vulkan/src/nativeMain/kotlin/com/kgl/vulkan/handles/AccelerationStructureNV.kt index 5c75a50..07ac203 100644 --- a/kgl-vulkan/src/nativeMain/kotlin/com/kgl/vulkan/handles/AccelerationStructureNV.kt +++ b/kgl-vulkan/src/nativeMain/kotlin/com/kgl/vulkan/handles/AccelerationStructureNV.kt @@ -15,7 +15,7 @@ */ package com.kgl.vulkan.handles -import com.kgl.core.ByteBuffer +import com.kgl.core.DirectMemory import com.kgl.core.VirtualStack import com.kgl.vulkan.dsls.AccelerationStructureMemoryRequirementsInfoNVBuilder import com.kgl.vulkan.enums.AccelerationStructureMemoryRequirementsTypeNV @@ -49,7 +49,7 @@ actual class AccelerationStructureNV(override val ptr: VkAccelerationStructureNV } } - actual fun getHandle(pData: ByteBuffer) { + actual fun getHandle(pData: DirectMemory) { val accelerationStructure = this val device = accelerationStructure.device VirtualStack.push() diff --git a/kgl-vulkan/src/nativeMain/kotlin/com/kgl/vulkan/handles/CommandBuffer.kt b/kgl-vulkan/src/nativeMain/kotlin/com/kgl/vulkan/handles/CommandBuffer.kt index 146fe2f..fab0b60 100644 --- a/kgl-vulkan/src/nativeMain/kotlin/com/kgl/vulkan/handles/CommandBuffer.kt +++ b/kgl-vulkan/src/nativeMain/kotlin/com/kgl/vulkan/handles/CommandBuffer.kt @@ -15,7 +15,7 @@ */ package com.kgl.vulkan.handles -import com.kgl.core.ByteBuffer +import com.kgl.core.DirectMemory import com.kgl.core.VirtualStack import com.kgl.vulkan.dsls.* import com.kgl.vulkan.enums.* @@ -429,7 +429,7 @@ actual class CommandBuffer(override val ptr: VkCommandBuffer, actual val command actual fun updateBuffer( dstBuffer: Buffer, dstOffset: ULong, - data: ByteBuffer + data: DirectMemory ) { val commandBuffer = this VirtualStack.push() @@ -644,7 +644,7 @@ actual class CommandBuffer(override val ptr: VkCommandBuffer, actual val command layout: PipelineLayout, stageFlags: VkFlag, offset: UInt, - values: ByteBuffer + values: DirectMemory ) { val commandBuffer = this VirtualStack.push() @@ -872,7 +872,7 @@ actual class CommandBuffer(override val ptr: VkCommandBuffer, actual val command descriptorUpdateTemplate: DescriptorUpdateTemplate, layout: PipelineLayout, set: UInt, - data: ByteBuffer + data: DirectMemory ) { val commandBuffer = this VirtualStack.push() @@ -1031,7 +1031,7 @@ actual class CommandBuffer(override val ptr: VkCommandBuffer, actual val command } } - actual fun setCheckpointNV(pCheckpointMarker: ByteBuffer) { + actual fun setCheckpointNV(pCheckpointMarker: DirectMemory) { val commandBuffer = this VirtualStack.push() try { diff --git a/kgl-vulkan/src/nativeMain/kotlin/com/kgl/vulkan/handles/DescriptorSet.kt b/kgl-vulkan/src/nativeMain/kotlin/com/kgl/vulkan/handles/DescriptorSet.kt index 059ef63..4d8d860 100644 --- a/kgl-vulkan/src/nativeMain/kotlin/com/kgl/vulkan/handles/DescriptorSet.kt +++ b/kgl-vulkan/src/nativeMain/kotlin/com/kgl/vulkan/handles/DescriptorSet.kt @@ -15,7 +15,7 @@ */ package com.kgl.vulkan.handles -import com.kgl.core.ByteBuffer +import com.kgl.core.DirectMemory import com.kgl.core.VirtualStack import com.kgl.vulkan.utils.VkHandle import com.kgl.vulkan.utils.VkHandleNative @@ -40,7 +40,7 @@ actual class DescriptorSet(override val ptr: VkDescriptorSet, actual val descrip } } - actual fun updateWithTemplate(descriptorUpdateTemplate: DescriptorUpdateTemplate, data: ByteBuffer) { + actual fun updateWithTemplate(descriptorUpdateTemplate: DescriptorUpdateTemplate, data: DirectMemory) { VirtualStack.push() try { dispatchTable.vkUpdateDescriptorSetWithTemplate!!(descriptorPool.device.toVkType(), toVkType(), diff --git a/kgl-vulkan/src/nativeMain/kotlin/com/kgl/vulkan/handles/Device.kt b/kgl-vulkan/src/nativeMain/kotlin/com/kgl/vulkan/handles/Device.kt index 2e225ef..ab604cb 100644 --- a/kgl-vulkan/src/nativeMain/kotlin/com/kgl/vulkan/handles/Device.kt +++ b/kgl-vulkan/src/nativeMain/kotlin/com/kgl/vulkan/handles/Device.kt @@ -15,7 +15,7 @@ */ package com.kgl.vulkan.handles -import com.kgl.core.ByteBuffer +import com.kgl.core.DirectMemory import com.kgl.core.VirtualStack import com.kgl.vulkan.dsls.* import com.kgl.vulkan.enums.* @@ -294,7 +294,7 @@ actual class Device(override val ptr: VkDevice, actual val physicalDevice: Physi } } - actual fun createPipelineCache(initialData: ByteBuffer?, block: PipelineCacheCreateInfoBuilder.() -> Unit): PipelineCache { + actual fun createPipelineCache(initialData: DirectMemory?, block: PipelineCacheCreateInfoBuilder.() -> Unit): PipelineCache { val device = this VirtualStack.push() try { @@ -555,7 +555,7 @@ actual class Device(override val ptr: VkDevice, actual val physicalDevice: Physi } } - actual fun debugMarkerSetObjectTagEXT(tag: ByteBuffer, block: DebugMarkerObjectTagInfoEXTBuilder.() -> Unit) { + actual fun debugMarkerSetObjectTagEXT(tag: DirectMemory, block: DebugMarkerObjectTagInfoEXTBuilder.() -> Unit) { val device = this VirtualStack.push() try { @@ -786,7 +786,7 @@ actual class Device(override val ptr: VkDevice, actual val physicalDevice: Physi } } - actual fun createValidationCacheEXT(initialData: ByteBuffer?, block: ValidationCacheCreateInfoEXTBuilder.() -> Unit): ValidationCacheEXT { + actual fun createValidationCacheEXT(initialData: DirectMemory?, block: ValidationCacheCreateInfoEXTBuilder.() -> Unit): ValidationCacheEXT { val device = this VirtualStack.push() try { @@ -836,7 +836,7 @@ actual class Device(override val ptr: VkDevice, actual val physicalDevice: Physi } } - actual fun setDebugUtilsObjectTagEXT(tag: ByteBuffer, block: DebugUtilsObjectTagInfoEXTBuilder.() -> Unit) { + actual fun setDebugUtilsObjectTagEXT(tag: DirectMemory, block: DebugUtilsObjectTagInfoEXTBuilder.() -> Unit) { val device = this VirtualStack.push() try { diff --git a/kgl-vulkan/src/nativeMain/kotlin/com/kgl/vulkan/handles/DeviceMemory.kt b/kgl-vulkan/src/nativeMain/kotlin/com/kgl/vulkan/handles/DeviceMemory.kt index 1cf153b..02d0873 100644 --- a/kgl-vulkan/src/nativeMain/kotlin/com/kgl/vulkan/handles/DeviceMemory.kt +++ b/kgl-vulkan/src/nativeMain/kotlin/com/kgl/vulkan/handles/DeviceMemory.kt @@ -15,7 +15,7 @@ */ package com.kgl.vulkan.handles -import com.kgl.core.ByteBuffer +import com.kgl.core.DirectMemory import com.kgl.core.VirtualStack import com.kgl.vulkan.dsls.MemoryGetFdInfoKHRBuilder import com.kgl.vulkan.utils.VkHandle @@ -61,7 +61,7 @@ actual class DeviceMemory( } } - actual fun map(offset: ULong, size: ULong): ByteBuffer { + actual fun map(offset: ULong, size: ULong): DirectMemory { val memory = this val device = memory.device VirtualStack.push() @@ -71,7 +71,7 @@ actual class DeviceMemory( val result = dispatchTable.vkMapMemory(device.toVkType(), memory.toVkType(), offset.toVkType(), size.toVkType(), 0U.toVkType(), outputPtr) if (result != VK_SUCCESS) handleVkResult(result) - return ByteBuffer(outputVar.value!!.reinterpret(), size.toLong()) + return DirectMemory(outputVar.value!!.reinterpret(), size.toLong()) } finally { VirtualStack.pop() } diff --git a/kgl-vulkan/src/nativeMain/kotlin/com/kgl/vulkan/handles/Pipeline.kt b/kgl-vulkan/src/nativeMain/kotlin/com/kgl/vulkan/handles/Pipeline.kt index c0eba95..95bf5c9 100644 --- a/kgl-vulkan/src/nativeMain/kotlin/com/kgl/vulkan/handles/Pipeline.kt +++ b/kgl-vulkan/src/nativeMain/kotlin/com/kgl/vulkan/handles/Pipeline.kt @@ -15,7 +15,7 @@ */ package com.kgl.vulkan.handles -import com.kgl.core.ByteBuffer +import com.kgl.core.DirectMemory import com.kgl.core.VirtualStack import com.kgl.vulkan.enums.ShaderInfoTypeAMD import com.kgl.vulkan.enums.ShaderStage @@ -44,7 +44,7 @@ actual class Pipeline(override val ptr: VkPipeline, actual val device: Device) : actual fun getShaderInfoAMD( shaderStage: ShaderStage, infoType: ShaderInfoTypeAMD, - info: ByteBuffer? + info: DirectMemory? ) { TODO() val pipeline = this @@ -77,7 +77,7 @@ actual class Pipeline(override val ptr: VkPipeline, actual val device: Device) : } } - actual fun getRayTracingShaderGroupHandlesNV(firstGroup: UInt, groupCount: UInt, data: ByteBuffer) { + actual fun getRayTracingShaderGroupHandlesNV(firstGroup: UInt, groupCount: UInt, data: DirectMemory) { val pipeline = this val device = pipeline.device VirtualStack.push() diff --git a/kgl-vulkan/src/nativeMain/kotlin/com/kgl/vulkan/handles/PipelineCache.kt b/kgl-vulkan/src/nativeMain/kotlin/com/kgl/vulkan/handles/PipelineCache.kt index 8bdc4fd..e5b61df 100644 --- a/kgl-vulkan/src/nativeMain/kotlin/com/kgl/vulkan/handles/PipelineCache.kt +++ b/kgl-vulkan/src/nativeMain/kotlin/com/kgl/vulkan/handles/PipelineCache.kt @@ -15,7 +15,7 @@ */ package com.kgl.vulkan.handles -import com.kgl.core.ByteBuffer +import com.kgl.core.DirectMemory import com.kgl.core.VirtualStack import com.kgl.vulkan.utils.VkHandle import com.kgl.vulkan.utils.VkHandleNative @@ -59,7 +59,7 @@ actual class PipelineCache(override val ptr: VkPipelineCache, actual val device: } } - actual fun getData(data: ByteBuffer): Boolean { + actual fun getData(data: DirectMemory): Boolean { val pipelineCache = this val device = pipelineCache.device VirtualStack.push() diff --git a/kgl-vulkan/src/nativeMain/kotlin/com/kgl/vulkan/handles/QueryPool.kt b/kgl-vulkan/src/nativeMain/kotlin/com/kgl/vulkan/handles/QueryPool.kt index 6a1b1d8..5deef74 100644 --- a/kgl-vulkan/src/nativeMain/kotlin/com/kgl/vulkan/handles/QueryPool.kt +++ b/kgl-vulkan/src/nativeMain/kotlin/com/kgl/vulkan/handles/QueryPool.kt @@ -15,7 +15,7 @@ */ package com.kgl.vulkan.handles -import com.kgl.core.ByteBuffer +import com.kgl.core.DirectMemory import com.kgl.core.VirtualStack import com.kgl.vulkan.enums.QueryResult import com.kgl.vulkan.utils.* @@ -41,7 +41,7 @@ actual class QueryPool(override val ptr: VkQueryPool, actual val device: Device) actual fun getResults( firstQuery: UInt, queryCount: UInt, - data: ByteBuffer, + data: DirectMemory, stride: ULong, flags: VkFlag? ): Boolean { diff --git a/kgl-vulkan/src/nativeMain/kotlin/com/kgl/vulkan/handles/ValidationCacheEXT.kt b/kgl-vulkan/src/nativeMain/kotlin/com/kgl/vulkan/handles/ValidationCacheEXT.kt index 7c2c0a0..8c0cd96 100644 --- a/kgl-vulkan/src/nativeMain/kotlin/com/kgl/vulkan/handles/ValidationCacheEXT.kt +++ b/kgl-vulkan/src/nativeMain/kotlin/com/kgl/vulkan/handles/ValidationCacheEXT.kt @@ -15,7 +15,7 @@ */ package com.kgl.vulkan.handles -import com.kgl.core.ByteBuffer +import com.kgl.core.DirectMemory import com.kgl.core.VirtualStack import com.kgl.vulkan.utils.VkHandle import com.kgl.vulkan.utils.VkHandleNative @@ -39,7 +39,7 @@ actual class ValidationCacheEXT(override val ptr: VkValidationCacheEXT, actual v } } - actual fun getData(data: ByteBuffer?) { + actual fun getData(data: DirectMemory?) { TODO() val validationCache = this val device = validationCache.device