-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
20 changed files
with
113 additions
and
133 deletions.
There are no files selected for viewing
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
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
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
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
2 changes: 1 addition & 1 deletion
2
...eline/backend/vk/util/KoolVkExtensions.kt → ...l/pipeline/backend/vk/KoolVkExtensions.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
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
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
66 changes: 0 additions & 66 deletions
66
kool-core/src/desktopMain/kotlin/de/fabmax/kool/pipeline/backend/vk/ShaderCodeImplVk.kt
This file was deleted.
Oops, something went wrong.
59 changes: 59 additions & 0 deletions
59
kool-core/src/desktopMain/kotlin/de/fabmax/kool/pipeline/backend/vk/ShaderCodeVk.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,59 @@ | ||
package de.fabmax.kool.pipeline.backend.vk | ||
|
||
import de.fabmax.kool.pipeline.ComputeShaderCode | ||
import de.fabmax.kool.pipeline.ShaderCode | ||
import de.fabmax.kool.pipeline.backend.vk.pipeline.ShaderStage | ||
import de.fabmax.kool.util.LongHash | ||
import de.fabmax.kool.util.logE | ||
import org.lwjgl.vulkan.VK10.* | ||
|
||
class ShaderCodeVk(val stages: List<ShaderStage>): ShaderCode, ComputeShaderCode { | ||
|
||
override val hash: LongHash = LongHash { | ||
stages.forEach { this += it.hash } | ||
} | ||
|
||
companion object { | ||
private val shaderCache = mutableMapOf<ShaderKey, ShaderStage>() | ||
|
||
fun drawShaderCode(vertShaderSrc: String, fragShaderSrc: String): ShaderCodeVk { | ||
try { | ||
val vertexStage = shaderCache.getOrPut(ShaderKey(vertShaderSrc, VK_SHADER_STAGE_VERTEX_BIT)) { | ||
ShaderStage.fromSource("vertShader", vertShaderSrc, VK_SHADER_STAGE_VERTEX_BIT) | ||
} | ||
val fragmentStage = shaderCache.getOrPut(ShaderKey(fragShaderSrc, VK_SHADER_STAGE_FRAGMENT_BIT)) { | ||
ShaderStage.fromSource("fragShader", fragShaderSrc, VK_SHADER_STAGE_FRAGMENT_BIT) | ||
} | ||
return ShaderCodeVk(listOf(vertexStage, fragmentStage)) | ||
} catch (e: Exception) { | ||
logE { "Compilation failed: $e" } | ||
dumpCode(listOf("Vertex shader" to vertShaderSrc, "Fragment shader" to fragShaderSrc)) | ||
throw RuntimeException(e) | ||
} | ||
} | ||
|
||
fun computeShaderCode(computeShaderSrc: String): ShaderCodeVk { | ||
try { | ||
val computeStage = shaderCache.getOrPut(ShaderKey(computeShaderSrc, VK_SHADER_STAGE_COMPUTE_BIT)) { | ||
ShaderStage.fromSource("computeShader", computeShaderSrc, VK_SHADER_STAGE_COMPUTE_BIT) | ||
} | ||
return ShaderCodeVk(listOf(computeStage)) | ||
} catch (e: Exception) { | ||
logE { "Compilation failed: $e" } | ||
dumpCode(listOf("Compute shader" to computeShaderSrc)) | ||
throw RuntimeException(e) | ||
} | ||
} | ||
|
||
private fun dumpCode(sources: List<Pair<String, String>>) { | ||
sources.forEach { (name, source) -> | ||
println("$name:\n\n") | ||
source.lines().forEachIndexed { i, l -> | ||
println(String.format("%3d: %s", i+1, l)) | ||
} | ||
} | ||
} | ||
} | ||
|
||
private data class ShaderKey(val src: String, val stageBit: Int) | ||
} |
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
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
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
1 change: 0 additions & 1 deletion
1
kool-core/src/desktopMain/kotlin/de/fabmax/kool/pipeline/backend/vk/VkOffscreenPass2d.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
1 change: 0 additions & 1 deletion
1
kool-core/src/desktopMain/kotlin/de/fabmax/kool/pipeline/backend/vk/VkOffscreenPassCube.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
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
Oops, something went wrong.