Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main'
Browse files Browse the repository at this point in the history
  • Loading branch information
fabmax committed Dec 26, 2023
2 parents 9a23f6f + bf6bac3 commit a0f0f51
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class ComputeRenderPass(name: String, width: Int, height: Int = 1, depth: Int =
val tasks: List<Task> get() {
if (isTasksDirty) {
_tasks
.filter { it.isCreated == false }
.filter { !it.isCreated }
.forEach { it.create(it.shader.getOrCreatePipeline(this)) }
isTasksDirty = false
}
Expand All @@ -45,8 +45,31 @@ class ComputeRenderPass(name: String, width: Int, height: Int = 1, depth: Int =
lateinit var pipeline: ComputePipeline
private set

private val beforeDispatch = mutableListOf<() -> Unit>()
private val afterDispatch = mutableListOf<() -> Unit>()

fun create(pipeline: ComputePipeline) {
this.pipeline = pipeline
}

fun onBeforeDispatch(block: () -> Unit) {
beforeDispatch += block
}

fun onAfterDispatch(block: () -> Unit) {
afterDispatch += block
}

internal fun beforeDispatch() {
for (i in beforeDispatch.indices) {
beforeDispatch[i]()
}
}

internal fun afterDispatch() {
for (i in afterDispatch.indices) {
afterDispatch[i]()
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -211,13 +211,17 @@ abstract class RenderBackendGl(internal val gl: GlApi, internal val ctx: KoolCon
val numGroupsY = ceil(computePass.height.toFloat() / pipeline.workGroupSize.y).toInt()
val numGroupsZ = ceil(computePass.depth.toFloat() / pipeline.workGroupSize.z).toInt()

task.beforeDispatch()

if (shaderMgr.setupComputeShader(pipeline, computePass)) {
val maxCnt = gl.capabilities.maxWorkGroupCount
if (numGroupsX > maxCnt.x || numGroupsY > maxCnt.y || numGroupsZ > maxCnt.z) {
logE { "Maximum compute shader workgroup count exceeded: max count = $maxCnt, requested count: ($numGroupsX, $numGroupsY, $numGroupsZ)" }
}
gl.dispatchCompute(numGroupsX, numGroupsY, numGroupsZ)
gl.memoryBarrier(gl.SHADER_IMAGE_ACCESS_BARRIER_BIT)

task.afterDispatch()
}
}
}
Expand Down

0 comments on commit a0f0f51

Please sign in to comment.