fix: rawmax stuck
This commit is contained in:
1 parent
ae789e62d9
commit
bd6f215c60
5 files changed
+131
-36
No files matched your search
+9
-10
@@ -39,6 +39,8 @@ internal class GlesRadianceVgnChromaPostprocessor(
|
||||
|
||||
fun checkGlError(label: String)
|
||||
|
||||
fun waitForGpuCheckpoint(label: String)
|
||||
|
||||
fun yieldToUiRenderer()
|
||||
}
|
||||
|
||||
@@ -405,11 +407,9 @@ internal class GlesRadianceVgnChromaPostprocessor(
|
||||
bindImage(0, originalYccd, GLES31.GL_READ_ONLY)
|
||||
bindImage(1, destination, GLES31.GL_WRITE_ONLY)
|
||||
// The result leaves this component and can be consumed as both an FBO attachment and a
|
||||
// sampler by the persistent RAW renderer.
|
||||
val nextAccessBarrier = GLES31.GL_SHADER_IMAGE_ACCESS_BARRIER_BIT or
|
||||
GLES31.GL_FRAMEBUFFER_BARRIER_BIT or
|
||||
GLES31.GL_TEXTURE_FETCH_BARRIER_BIT
|
||||
dispatchImage(finalProgram, "final camera RGB", nextAccessBarrier)
|
||||
// sampler by the persistent RAW renderer. dispatchImage establishes the full barrier and
|
||||
// completion boundary before ownership is transferred.
|
||||
dispatchImage(finalProgram, "final camera RGB")
|
||||
}
|
||||
|
||||
private fun runIirRgb(
|
||||
@@ -491,12 +491,11 @@ internal class GlesRadianceVgnChromaPostprocessor(
|
||||
private fun dispatchImage(
|
||||
program: Int,
|
||||
label: String,
|
||||
barrierBits: Int = GLES31.GL_SHADER_IMAGE_ACCESS_BARRIER_BIT,
|
||||
) {
|
||||
GLES31.glDispatchCompute(groupCount(imageWidth), groupCount(imageHeight), 1)
|
||||
GLES31.glMemoryBarrier(barrierBits)
|
||||
GLES31.glMemoryBarrier(GLES31.GL_ALL_BARRIER_BITS)
|
||||
backend.checkGlError("Radiance VGN chroma $label")
|
||||
backend.yieldToUiRenderer()
|
||||
backend.waitForGpuCheckpoint(label)
|
||||
}
|
||||
|
||||
private fun dispatchIir(axis: Int, label: String) {
|
||||
@@ -505,9 +504,9 @@ internal class GlesRadianceVgnChromaPostprocessor(
|
||||
} else {
|
||||
GLES31.glDispatchCompute(imageWidth, 1, 1)
|
||||
}
|
||||
GLES31.glMemoryBarrier(GLES31.GL_SHADER_IMAGE_ACCESS_BARRIER_BIT)
|
||||
GLES31.glMemoryBarrier(GLES31.GL_ALL_BARRIER_BITS)
|
||||
backend.checkGlError("Radiance VGN chroma $label")
|
||||
backend.yieldToUiRenderer()
|
||||
backend.waitForGpuCheckpoint(label)
|
||||
}
|
||||
|
||||
private fun setImageUniforms(program: Int) {
|
||||
|
||||
@@ -1246,6 +1246,12 @@ internal class GlesRawRadianceStacker(
|
||||
this@GlesRawRadianceStacker.checkGlError(label)
|
||||
}
|
||||
|
||||
override fun waitForGpuCheckpoint(label: String) {
|
||||
this@GlesRawRadianceStacker.waitForRadianceGpuCheckpoint(
|
||||
"chroma $label",
|
||||
)
|
||||
}
|
||||
|
||||
override fun yieldToUiRenderer() {
|
||||
GlesGpuScheduler.yieldToUiRenderer()
|
||||
}
|
||||
@@ -6004,6 +6010,9 @@ internal class GlesRawRadianceStacker(
|
||||
recordFusionRejections = false,
|
||||
)
|
||||
captureRadianceReferenceBase(tile.outputWorking.width, tile.outputWorking.height)
|
||||
waitForRadianceGpuCheckpoint(
|
||||
"tile ${tile.index + 1}/${radianceTiles.size} reference fused",
|
||||
)
|
||||
|
||||
acceptedFrames.forEachIndexed { statsFrameIndex, frame ->
|
||||
val sourceRegion = radianceSourceRegion(tile, frame.flowBounds())
|
||||
@@ -6032,6 +6041,10 @@ internal class GlesRawRadianceStacker(
|
||||
recordFusionRejections = rejectionNormalFrame != null &&
|
||||
statsFrameIndex == rejectionFrameOrdinal,
|
||||
)
|
||||
waitForRadianceGpuCheckpoint(
|
||||
"tile ${tile.index + 1}/${radianceTiles.size} " +
|
||||
"normal frame ${frame.frameIndex} fused",
|
||||
)
|
||||
}
|
||||
|
||||
longAlignments.forEachIndexed { longIndex, alignment ->
|
||||
@@ -6061,6 +6074,10 @@ internal class GlesRawRadianceStacker(
|
||||
recordFusionRejections = rejectionLongFrame != null &&
|
||||
longIndex == rejectionLongIndex,
|
||||
)
|
||||
waitForRadianceGpuCheckpoint(
|
||||
"tile ${tile.index + 1}/${radianceTiles.size} " +
|
||||
"long frame ${alignment.plan.sourceFrameIndex} fused",
|
||||
)
|
||||
}
|
||||
|
||||
val highlightSourceRegion = highlightAlignment?.let { highlight ->
|
||||
@@ -6092,7 +6109,9 @@ internal class GlesRawRadianceStacker(
|
||||
totalPixelTransferMs += timing.pixelTransferMs
|
||||
totalCpuPackMs += timing.cpuPackMs
|
||||
}
|
||||
GlesGpuScheduler.yieldToUiRenderer()
|
||||
waitForRadianceGpuCheckpoint(
|
||||
"tile ${tile.index + 1}/${radianceTiles.size} normalized",
|
||||
)
|
||||
}
|
||||
if (chromaPostprocessor != null) {
|
||||
GLES31.glMemoryBarrier(GLES31.GL_SHADER_IMAGE_ACCESS_BARRIER_BIT)
|
||||
@@ -6315,11 +6334,24 @@ internal class GlesRawRadianceStacker(
|
||||
GLES31.glBindBuffer(GLES31.GL_UNIFORM_BUFFER, 0)
|
||||
}
|
||||
GLES31.glDispatchCompute(groupCountX.coerceAtLeast(1), groupCountY.coerceAtLeast(1), 1)
|
||||
// Every following VGN stage consumes an image written by the preceding stage. A GPU
|
||||
// memory barrier is sufficient; unlike the single-frame path, tiled Radiance must not
|
||||
// insert a CPU-visible fence after each pass.
|
||||
GLES31.glMemoryBarrier(GLES31.GL_SHADER_IMAGE_ACCESS_BARRIER_BIT)
|
||||
// Radiance repeatedly reuses the same VGN images and UBO for every frame in every tile.
|
||||
// A memory barrier only establishes visibility; the checkpoint also bounds the
|
||||
// background compute queue before those resources are updated by the next pass.
|
||||
GLES31.glMemoryBarrier(GLES31.GL_ALL_BARRIER_BITS)
|
||||
checkGlError("Radiance VGN $label")
|
||||
waitForRadianceGpuCheckpoint("VGN $label")
|
||||
}
|
||||
|
||||
private fun waitForRadianceGpuCheckpoint(label: String) {
|
||||
val startNs = System.nanoTime()
|
||||
/*RawStackRuntimeDebug.d(TAG) {
|
||||
"Radiance GPU checkpoint waiting label=$label"
|
||||
}*/
|
||||
GlesGpuScheduler.waitForGpuCheckpoint(TAG, "Radiance $label")
|
||||
/*RawStackRuntimeDebug.d(TAG) {
|
||||
"Radiance GPU checkpoint complete label=$label " +
|
||||
"elapsedMs=${(System.nanoTime() - startNs) / 1_000_000L}"
|
||||
}*/
|
||||
}
|
||||
|
||||
private fun runRadianceReferenceVgn(sourceRegion: RadianceTileRect, label: String) {
|
||||
@@ -6382,8 +6414,9 @@ internal class GlesRawRadianceStacker(
|
||||
GLES31.glUniform1i(uniformLocation(prepare, "uReconstructHighlights"), 1)
|
||||
bindImage(0, radianceVgnPackedFloatTexture, GLES31.GL_WRITE_ONLY, GLES30.GL_RGBA16F)
|
||||
GLES31.glDispatchCompute(groupsPackedX, groupsWorkY, 1)
|
||||
GLES31.glMemoryBarrier(GLES31.GL_SHADER_IMAGE_ACCESS_BARRIER_BIT)
|
||||
GLES31.glMemoryBarrier(GLES31.GL_ALL_BARRIER_BITS)
|
||||
checkGlError("$label VGN prepare")
|
||||
waitForRadianceGpuCheckpoint("$label VGN prepare")
|
||||
|
||||
dispatchRadianceVgnPass(
|
||||
radianceVgnPrograms[VgnShaders.PROGRAM_NEUTRAL],
|
||||
@@ -6633,10 +6666,9 @@ internal class GlesRawRadianceStacker(
|
||||
GLES30.GL_RGBA16F,
|
||||
)
|
||||
GLES31.glDispatchCompute(groupCount(sourceRegion.width), groupCount(sourceRegion.height), 1)
|
||||
GLES31.glMemoryBarrier(
|
||||
GLES31.GL_SHADER_IMAGE_ACCESS_BARRIER_BIT or GLES31.GL_TEXTURE_FETCH_BARRIER_BIT,
|
||||
)
|
||||
GLES31.glMemoryBarrier(GLES31.GL_ALL_BARRIER_BITS)
|
||||
checkGlError("$label VGN camera RGB")
|
||||
waitForRadianceGpuCheckpoint("$label VGN camera RGB")
|
||||
}
|
||||
|
||||
private fun runRadianceSemanticProxy(sourceRegion: RadianceTileRect, label: String) {
|
||||
@@ -6671,8 +6703,9 @@ internal class GlesRawRadianceStacker(
|
||||
GLES30.GL_RGBA16F,
|
||||
)
|
||||
GLES31.glDispatchCompute(groupCount(sourceRegion.width), groupCount(sourceRegion.height), 1)
|
||||
GLES31.glMemoryBarrier(GLES31.GL_SHADER_IMAGE_ACCESS_BARRIER_BIT)
|
||||
GLES31.glMemoryBarrier(GLES31.GL_ALL_BARRIER_BITS)
|
||||
checkGlError("$label semantic seed")
|
||||
waitForRadianceGpuCheckpoint("$label semantic seed")
|
||||
|
||||
val resolve = radianceSemanticResolveProgram
|
||||
GLES31.glUseProgram(resolve)
|
||||
@@ -6701,10 +6734,9 @@ internal class GlesRawRadianceStacker(
|
||||
GLES30.GL_RGBA16F,
|
||||
)
|
||||
GLES31.glDispatchCompute(groupCount(sourceRegion.width), groupCount(sourceRegion.height), 1)
|
||||
GLES31.glMemoryBarrier(
|
||||
GLES31.GL_SHADER_IMAGE_ACCESS_BARRIER_BIT or GLES31.GL_TEXTURE_FETCH_BARRIER_BIT,
|
||||
)
|
||||
GLES31.glMemoryBarrier(GLES31.GL_ALL_BARRIER_BITS)
|
||||
checkGlError("$label semantic resolve")
|
||||
waitForRadianceGpuCheckpoint("$label semantic resolve")
|
||||
}
|
||||
|
||||
private fun normalizeRadianceTile(
|
||||
|
||||
@@ -6536,8 +6536,9 @@ class RawDemosaicProcessor {
|
||||
rowCount = height,
|
||||
width = width,
|
||||
)
|
||||
finishLinearRawUint16ToFloat()
|
||||
checkGlError("renderLinearRawRgbToTexture RGBA16UI")
|
||||
finishLinearRawUint16ToFloat(
|
||||
"LinearRaw RGBA16UI to RGBA16F ${width}x$height",
|
||||
)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -6593,11 +6594,11 @@ class RawDemosaicProcessor {
|
||||
rowCount = rowCount,
|
||||
width = width,
|
||||
)
|
||||
GLES31.glMemoryBarrier(GLES31.GL_SHADER_IMAGE_ACCESS_BARRIER_BIT)
|
||||
finishLinearRawUint16ToFloat(
|
||||
"LinearRaw RGB16UI to RGBA16F rows=$sourceY..${sourceY + rowCount}",
|
||||
)
|
||||
sourceY += rowCount
|
||||
}
|
||||
finishLinearRawUint16ToFloat()
|
||||
checkGlError("renderLinearRawRgbToTexture RGB16UI")
|
||||
} finally {
|
||||
GLES31.glBindImageTexture(
|
||||
0,
|
||||
@@ -6684,12 +6685,8 @@ class RawDemosaicProcessor {
|
||||
GLES31.glDispatchCompute(GlesComputeWorkGroup.imageGroupCount(width), GlesComputeWorkGroup.imageGroupCount(rowCount), 1)
|
||||
}
|
||||
|
||||
private fun finishLinearRawUint16ToFloat() {
|
||||
GLES31.glMemoryBarrier(
|
||||
GLES31.GL_SHADER_IMAGE_ACCESS_BARRIER_BIT or
|
||||
GLES31.GL_TEXTURE_FETCH_BARRIER_BIT or
|
||||
GLES31.GL_FRAMEBUFFER_BARRIER_BIT
|
||||
)
|
||||
private fun finishLinearRawUint16ToFloat(label: String) {
|
||||
GLES31.glMemoryBarrier(GLES31.GL_ALL_BARRIER_BITS)
|
||||
GLES31.glBindImageTexture(
|
||||
0,
|
||||
0,
|
||||
@@ -6708,6 +6705,15 @@ class RawDemosaicProcessor {
|
||||
GLES31.GL_WRITE_ONLY,
|
||||
GLES31.GL_RGBA16F
|
||||
)
|
||||
checkGlError(label)
|
||||
val startNs = System.nanoTime()
|
||||
PLog.d(TAG, "RAW GPU checkpoint waiting label=$label")
|
||||
GlesGpuScheduler.waitForGpuCheckpoint(TAG, label)
|
||||
PLog.d(
|
||||
TAG,
|
||||
"RAW GPU checkpoint complete label=$label " +
|
||||
"elapsedMs=${(System.nanoTime() - startNs) / 1_000_000L}",
|
||||
)
|
||||
}
|
||||
|
||||
internal fun createFramebufferForTexture(textureId: Int, label: String): Int {
|
||||
|
||||
@@ -72,14 +72,14 @@ object VideoCapabilitiesResolver {
|
||||
?: availableFps.firstOrNull()
|
||||
?: VideoFpsPreset.FPS_30
|
||||
|
||||
PLog.d(
|
||||
/*PLog.d(
|
||||
TAG,
|
||||
"Resolved video capabilities: resolution=${resolvedResolution.displayName}, " +
|
||||
"recording=${recordingSize.width}x${recordingSize.height}, " +
|
||||
"cameraInput=${cameraInputSize.width}x${cameraInputSize.height}, " +
|
||||
"preview=${previewSize.width}x${previewSize.height}, " +
|
||||
"fps=${availableFps.map { it.fps }}"
|
||||
)
|
||||
)*/
|
||||
|
||||
val linearTonemapSupported = availableTonemapModes.contains(CaptureRequest.TONEMAP_MODE_CONTRAST_CURVE) ||
|
||||
availableTonemapModes.contains(CaptureRequest.TONEMAP_MODE_GAMMA_VALUE)
|
||||
|
||||
@@ -327,6 +327,64 @@ image load/store 访问。若同一纹理接下来改由 sampler 读取,或作
|
||||
- GPU 纹理跨组件交接的真机测试必须实际执行 `imageStore -> barrier -> sampler fetch`,并覆盖
|
||||
左上角、图像内部和右下角,不能只验证 program 编译或 CPU readback。
|
||||
|
||||
## Mali 后台 compute 队列与可变资源复用
|
||||
|
||||
已确认设备:OPPO PKD130,MT6835,Mali-G57 MC2,驱动 `v1.r38p1`。
|
||||
|
||||
### 问题
|
||||
|
||||
Radiance tiled reconstruction 会在一个 tile 内连续提交多帧 VGN/semantic compute 和
|
||||
framebuffer fusion,并为下一帧重复使用同一组 image、UBO、RGB tile,以及通过
|
||||
`glTexSubImage2D` 覆写同一张 RAW region texture。仅在各 pass 后调用 `glMemoryBarrier`,
|
||||
最后才 `glFlush`/`Thread.yield`,可能让后台队列长期保持大量未完成工作。该设备会在第一个
|
||||
Radiance tile 内停止推进,应用没有 Java/native crash 或 ANR;关闭 long frame 只能少提交一帧,
|
||||
不能消除问题。只限制 tiled reconstruction 后,12 个 tile 可以完成,但未切片的全帧 chroma
|
||||
local/IIR 链、最终导出和紧随其后的 `RGBA16UI → RGBA16F` 转换仍会把同类停滞后移到
|
||||
EngineTone 开始处。相同分辨率的单帧 VGN 使用分 pass checkpoint 时可以正常完成。
|
||||
|
||||
`glMemoryBarrier` 只声明指定访问类型之间的内存可见性和顺序,不表示 GPU 已完成,也不保证
|
||||
CPU 紧接着覆写的 UBO/texture 已不再被旧命令读取。`glFlush` 只提交命令,同样不是资源复用
|
||||
完成边界。
|
||||
|
||||
### 错误做法
|
||||
|
||||
- 把一个 tile 的所有帧和 pass 一次性排入后台 context,只在 tile 末尾 `glFlush`。
|
||||
- 只增加 barrier bits,然后立即用 `glBufferData` 或 `glTexSubImage2D` 更新仍可能被旧命令
|
||||
使用的同一资源。
|
||||
- 认为关闭 long frame 后仍卡住,说明问题与多帧 GPU 队列无关。
|
||||
- 用一个覆盖整条 Radiance 链的 `glFinish` 代替调度;这会长期阻塞 CPU,也不给 UI renderer
|
||||
留出稳定调度窗口。
|
||||
|
||||
### 正确做法
|
||||
|
||||
- VGN prepare、每个 VGN compute pass、最终 camera RGB,以及 semantic seed/resolve 完成后,
|
||||
先使用 `GL_ALL_BARRIER_BITS` 建立完整访问交接,再通过
|
||||
`GlesGpuScheduler.waitForGpuCheckpoint` 限制后台队列深度。
|
||||
- 每帧 fusion 完成后建立 checkpoint,确认该帧对 RAW region、semantic/RGB tile、UBO 和
|
||||
accumulator 的访问结束,再上传下一帧到复用资源。
|
||||
- reference fusion 与 reference-base capture 作为一个资源复用单元;两者完成后再开始下一帧。
|
||||
- 每个 tile normalization 和输出标记/回读后建立 checkpoint,再清零并复用 accumulator 处理
|
||||
下一 tile。
|
||||
- 全帧 chroma local pass、每个水平/垂直 IIR direction 和最终 camera RGB 导出同样建立
|
||||
checkpoint。ping-pong texture 交换 Java/Kotlin 变量不代表 GPU 已结束旧角色的访问。
|
||||
- 下游把导出的 `RGBA16UI` 转成 `RGBA16F` 后建立 checkpoint,再允许 EngineTone fragment
|
||||
sampler 读取目标 texture。三通道条带转换还必须在每个条带结束后等待,才能覆写复用的
|
||||
expansion texture。
|
||||
- checkpoint 使用 fence 加短周期等待,并在完成后为 UI renderer 留出短暂调度窗口;保留等待
|
||||
前后的 stage label 和耗时日志,出现驱动停滞时能定位到具体 pass/frame/tile。
|
||||
- 这里只在后台重计算链的资源复用边界等待。已经完成、只读且要交给下游的输出 texture 仍按
|
||||
GPU→GPU 所有权交接处理,不额外执行 `glFinish` 或 CPU materialization。
|
||||
|
||||
### 验证
|
||||
|
||||
- 同一设备分别测试 long frame 开启和关闭,确认所有 tile、色度后处理和最终导出均完成。
|
||||
- 检查 checkpoint 的 waiting/complete 日志成对出现;若停滞,最后一个 waiting label 必须能
|
||||
唯一定位对应 VGN pass、semantic pass、frame fusion、chroma/IIR direction 或 LinearRaw
|
||||
格式转换。
|
||||
- 拍照处理期间持续操作预览 UI,确认 renderer 可推进且应用可响应。
|
||||
- 对修复前后的可正常完成设备比较输出;checkpoint 只改变命令完成边界,不应改变帧选择、
|
||||
shader 参数、累加顺序或像素结果。
|
||||
|
||||
## IMG/PowerVR `imageSize` 研究线索
|
||||
|
||||
### 问题
|
||||
|
||||
Reference in new issue
Block a user