-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement createShaderModule and createPipelineLayout functions in wgpu
The functions createShaderModule and createPipelineLayout were added to classes Device.jvm and Device.js, allowing for the creation of shader modules and pipeline layouts. A simple triangle scene was initialized to demonstrate these new functionalities. Corresponding changes were made in the ShaderModule files across the main and JVM platforms.
- Loading branch information
1 parent
66627aa
commit 07636e0
Showing
8 changed files
with
129 additions
and
4 deletions.
There are no files selected for viewing
35 changes: 35 additions & 0 deletions
35
...ings/wgpu/examples/src/commonMain/kotlin/io.ygdrasil.wgpu.examples/SimpleTriangleScene.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package io.ygdrasil.wgpu.examples | ||
|
||
import io.ygdrasil.wgpu.ShaderModuleDescriptor | ||
|
||
class SimpleTriangleScene : Application.Scene() { | ||
override fun Application.initialiaze() { | ||
val shaderModule = device.createShaderModule( | ||
ShaderModuleDescriptor( | ||
code = shader | ||
) | ||
) | ||
|
||
val pipeline = device.createPipelineLayout() | ||
|
||
TODO("Not yet implemented") | ||
} | ||
|
||
override fun Application.render() { | ||
TODO("Not yet implemented") | ||
} | ||
} | ||
|
||
private val shader = """ | ||
@vertex | ||
fn vs_main(@builtin(vertex_index) in_vertex_index: u32) -> @builtin(position) vec4<f32> { | ||
let x = f32(i32(in_vertex_index) - 1); | ||
let y = f32(i32(in_vertex_index & 1u) * 2 - 1); | ||
return vec4<f32>(x, y, 0.0, 1.0); | ||
} | ||
@fragment | ||
fn fs_main() -> @location(0) vec4<f32> { | ||
return vec4<f32>(1.0, 0.0, 0.0, 1.0); | ||
} | ||
""".trimIndent() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
bindings/wgpu/wgpu4k/src/commonMain/kotlin/io.ygdrasil.wgpu/ShaderModule.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package io.ygdrasil.wgpu | ||
|
||
expect class ShaderModule { | ||
} | ||
|
||
data class ShaderModuleDescriptor( | ||
var code: String, | ||
var label: String? = null, | ||
var sourceMap: Any? = null, | ||
var compilationHints: Array<CompilationHint>? = null | ||
) { | ||
data class CompilationHint( | ||
var entryPoint: String, | ||
// TODO | ||
//var layout: dynamic /* GPUPipelineLayout? | "auto" */ | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
bindings/wgpu/wgpu4k/src/jsMain/kotlin/io.ygdrasil.wgpu/ShaderModule.js.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package io.ygdrasil.wgpu | ||
|
||
import io.ygdrasil.wgpu.internal.js.GPUShaderModule | ||
import io.ygdrasil.wgpu.internal.js.GPUShaderModuleCompilationHint | ||
import io.ygdrasil.wgpu.internal.js.GPUShaderModuleDescriptor | ||
|
||
actual class ShaderModule(internal val handler: GPUShaderModule) { | ||
} | ||
|
||
fun ShaderModuleDescriptor.convert(): GPUShaderModuleDescriptor = object : GPUShaderModuleDescriptor { | ||
override var code: String = this@convert.code | ||
override var sourceMap: Any? = this@convert.sourceMap ?: undefined | ||
override var compilationHints: Array<GPUShaderModuleCompilationHint>? = this@convert | ||
.compilationHints | ||
?.map { it.convert() } | ||
?.toTypedArray() | ||
?: undefined | ||
override var label: String? = this@convert.label ?: undefined | ||
|
||
} | ||
|
||
private fun ShaderModuleDescriptor.CompilationHint.convert() = object : GPUShaderModuleCompilationHint { | ||
override var entryPoint: String = this@convert.entryPoint | ||
override var layout: dynamic = TODO("no yet implemented")//[email protected] ?: undefined | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
bindings/wgpu/wgpu4k/src/jvmMain/kotlin/io.ygdrasil.wgpu/ShaderModule.jvm.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package io.ygdrasil.wgpu | ||
|
||
import com.sun.jna.NativeLong | ||
import io.ygdrasil.wgpu.internal.jvm.* | ||
|
||
actual class ShaderModule(internal val handler: WGPUShaderModule?) : AutoCloseable { | ||
override fun close() { | ||
wgpuShaderModuleRelease(handler) | ||
} | ||
} | ||
|
||
|
||
internal fun ShaderModuleDescriptor.convert(): WGPUShaderModuleDescriptor = WGPUShaderModuleDescriptor().also { | ||
it.label = label | ||
it.nextInChain = WGPUShaderModuleWGSLDescriptor.ByReference().also { | ||
it.code = code | ||
it.chain.apply { | ||
sType = WGPUSType.WGPUSType_ShaderModuleWGSLDescriptor.value | ||
} | ||
} | ||
it.hintCount = NativeLong(compilationHints.size) | ||
it.hints = compilationHints.map { it.convert() } | ||
|
||
} | ||
|
||
private fun ShaderModuleDescriptor.CompilationHint.convert() = WGPUShaderModuleCompilationHint.ByReference().also { | ||
TODO("no yet implemented") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters