diff --git a/app/src/main/cpp/CMakeLists.txt b/app/src/main/cpp/CMakeLists.txt index 4dd77c86..a8b5fcde 100644 --- a/app/src/main/cpp/CMakeLists.txt +++ b/app/src/main/cpp/CMakeLists.txt @@ -158,50 +158,11 @@ set_source_files_properties( OBJECT_DEPENDS "${MGC_RAISR_FILTERS};${MGC_RAISR_RANDOMNESS_LUT}" ) -set( - MGC_SPATIAL_RGB_CAPSULE - "${CMAKE_CURRENT_SOURCE_DIR}/mgc_denoise_static/mgc_spatial_rgb_merge_capsule.bin" -) -set( - MGC_SPATIAL_RGB_CAPSULE_SHA256 - "196c4fb671a4c1e0667518d334474afd6f81a35a01acfd9d385089630a58eddd" -) -if(NOT EXISTS "${MGC_SPATIAL_RGB_CAPSULE}") - message( - FATAL_ERROR - "MGC Spatial RGB Merge capsule is missing; regenerate it with " - "scripts/research/generate_mgc_spatial_rgb_merge_static_asm.py" - ) -endif() -file( - SHA256 - "${MGC_SPATIAL_RGB_CAPSULE}" - MGC_SPATIAL_RGB_CAPSULE_ACTUAL_SHA256 -) -if(NOT MGC_SPATIAL_RGB_CAPSULE_ACTUAL_SHA256 STREQUAL MGC_SPATIAL_RGB_CAPSULE_SHA256) - message(FATAL_ERROR "MGC Spatial RGB Merge capsule hash mismatch") -endif() -set( - MGC_SPATIAL_RGB_ASM - "${CMAKE_CURRENT_BINARY_DIR}/mgc_spatial_rgb_merge_static.S" -) -configure_file( - "${CMAKE_CURRENT_SOURCE_DIR}/mgc_denoise_static/mgc_spatial_rgb_merge_static.S.in" - "${MGC_SPATIAL_RGB_ASM}" - @ONLY -) -set_source_files_properties( - "${MGC_SPATIAL_RGB_ASM}" - PROPERTIES - OBJECT_DEPENDS "${MGC_SPATIAL_RGB_CAPSULE}" -) - # These are configure-time outputs, so do not mark them GENERATED: Ninja clean # would delete them without a build-time command to recreate them. Track them # as configure dependencies so a missing output also causes CMake to regenerate it. set_property( DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS - "${MGC_SPATIAL_RGB_ASM}" "${MGC_RAISR_ASM}" "${MGC_RAISR_TABLES_ASM}" "${MGC_POLYSHARP_ASM}" @@ -316,7 +277,6 @@ add_library(my-native-lib SHARED lut_processor.cpp dcp_parser.cpp mgc_denoise_static/mgc_halide_runtime.cpp - mgc_denoise_static/mgc_spatial_rgb_merge_jni.cpp raw_float_texture_transfer_jni.cpp mgc_denoise_static/mgc_raisr_jni.cpp mgc_denoise_static/mgc_raisr_driver.cpp @@ -324,7 +284,6 @@ add_library(my-native-lib SHARED "${MGC_RAISR_ASM}" "${MGC_RAISR_TABLES_ASM}" "${MGC_POLYSHARP_ASM}" - "${MGC_SPATIAL_RGB_ASM}" ${LIBRAW_SOURCES} ${ADOBE_DNG_SOURCES} ) diff --git a/app/src/main/cpp/mgc_denoise_static/mgc_spatial_rgb_merge_capsule.bin b/app/src/main/cpp/mgc_denoise_static/mgc_spatial_rgb_merge_capsule.bin deleted file mode 100644 index a66886a8..00000000 Binary files a/app/src/main/cpp/mgc_denoise_static/mgc_spatial_rgb_merge_capsule.bin and /dev/null differ diff --git a/app/src/main/cpp/mgc_denoise_static/mgc_spatial_rgb_merge_jni.cpp b/app/src/main/cpp/mgc_denoise_static/mgc_spatial_rgb_merge_jni.cpp deleted file mode 100644 index 09cacef5..00000000 --- a/app/src/main/cpp/mgc_denoise_static/mgc_spatial_rgb_merge_jni.cpp +++ /dev/null @@ -1,377 +0,0 @@ -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include - -namespace { - -constexpr char kTag[] = "PLog_MgcSpatialRgbAot"; - -struct HalideType { - uint8_t code; - uint8_t bits; - uint16_t lanes; -}; - -struct HalideDimension { - int32_t min; - int32_t extent; - int32_t stride; - uint32_t flags; -}; - -struct HalideBuffer { - uint64_t device; - const void* device_interface; - uint8_t* host; - uint64_t flags; - HalideType type; - int32_t dimensions; - const HalideDimension* dim; - void* padding; -}; - -static_assert(sizeof(HalideBuffer) == 56); -static_assert(sizeof(HalideDimension) == 16); -static_assert(offsetof(HalideBuffer, type) == 32); -static_assert(offsetof(HalideBuffer, dimensions) == 36); -static_assert(offsetof(HalideBuffer, dim) == 40); - -constexpr HalideType kUInt8 = {1, 8, 1}; -constexpr HalideType kUInt16 = {1, 16, 1}; -constexpr HalideType kUInt64 = {1, 64, 1}; -constexpr HalideType kFloat16 = {2, 16, 1}; -constexpr HalideType kFloat32 = {2, 32, 1}; - -constexpr int32_t Camera2CfaToMgcBayerPattern(int cfa_pattern) { - switch (cfa_pattern) { - case 0: - return 1; // RGGB - case 1: - return 3; // GRBG - case 2: - return 4; // GBRG - case 3: - return 2; // BGGR - default: - return 0; - } -} - -HalideBuffer MakeBuffer( - void* host, - HalideType type, - const HalideDimension* dimensions, - int dimension_count) { - HalideBuffer buffer = {}; - buffer.host = static_cast(host); - buffer.type = type; - buffer.dimensions = dimension_count; - buffer.dim = dimensions; - return buffer; -} - -bool CopyFloatArray( - JNIEnv* env, - jfloatArray source, - int expected_size, - std::vector* output, - bool require_positive) { - if (source == nullptr || env->GetArrayLength(source) != expected_size) return false; - output->resize(expected_size); - env->GetFloatArrayRegion(source, 0, expected_size, output->data()); - if (env->ExceptionCheck()) return false; - return std::all_of(output->begin(), output->end(), [require_positive](float value) { - return std::isfinite(value) && (!require_positive || value > 0.0f); - }); -} - -bool CheckedProduct(std::initializer_list factors, int64_t* result) { - int64_t value = 1; - for (const int64_t factor : factors) { - if (factor <= 0 || value > std::numeric_limits::max() / factor) return false; - value *= factor; - } - *result = value; - return true; -} - -} // namespace - -// Exact generated ABI at MGC 9.7.047 V25 libgcastartup.so+0x371990c. -extern "C" int photon_mgc_merge_rgb_raw16_f16_tile16_halide( - void* user_context, - int32_t bayer_pattern, - HalideBuffer* base_frame, - HalideBuffer* burst_ptrs, - HalideBuffer* alignment, - HalideBuffer* rejection_masks, - HalideBuffer* frame_weights, - HalideBuffer* wb_gains, - HalideBuffer* input_black_levels_rgb, - HalideBuffer* input_black_levels_rggb, - HalideBuffer* input_gains, - float overall_gain, - float merge_sharpness, - HalideBuffer* kernel_sigmas, - int32_t output_width, - int32_t output_height, - HalideBuffer* output); - -extern "C" JNIEXPORT jint JNICALL -Java_com_hinnka_mycamera_processor_MgcSpatialRgbMerger_nativeMerge( - JNIEnv* env, - jobject, - jobjectArray raw_buffers, - jintArray raw_offsets_array, - jintArray raw_row_strides_array, - jobject alignment_buffer, - jint alignment_width, - jint alignment_height, - jobject rejection_buffer, - jint rejection_width, - jint rejection_height, - jfloatArray frame_weights_array, - jfloatArray wb_gains_array, - jfloatArray input_black_levels_rgb_array, - jfloatArray input_black_levels_rggb_array, - jfloatArray input_gains_array, - jfloat overall_gain, - jfloat merge_sharpness, - jfloatArray kernel_sigmas_array, - jint raw_width, - jint raw_height, - jint output_width, - jint output_height, - jint output_storage_width, - jint output_storage_height, - jint cfa_pattern, - jobject output_buffer) { - const int32_t mgc_pattern = Camera2CfaToMgcBayerPattern(cfa_pattern); - const int frame_count = raw_buffers != nullptr - ? env->GetArrayLength(raw_buffers) - : 0; - const int64_t expected_alignment_width = - (static_cast(output_width) + 15) / 16; - const int64_t expected_alignment_height = - (static_cast(output_height) + 15) / 16; - // V25's rejection slices describe complete RAW/4 cells, not padded output - // storage. MergeRgb clamps sampling to the supplied rejection extents. - const int64_t expected_rejection_width = raw_width / 4; - const int64_t expected_rejection_height = raw_height / 4; - if (frame_count <= 0 || raw_offsets_array == nullptr || - raw_row_strides_array == nullptr || alignment_buffer == nullptr || - rejection_buffer == nullptr || output_buffer == nullptr || - env->GetArrayLength(raw_offsets_array) != frame_count || - env->GetArrayLength(raw_row_strides_array) != frame_count || - raw_width <= 0 || raw_height <= 0 || output_width <= 0 || - output_height <= 0 || output_storage_width <= 0 || - output_storage_height <= 0 || (output_storage_width & 15) != 0 || - (output_storage_height & 15) != 0 || - output_storage_width != expected_alignment_width * 16 || - output_storage_height != expected_alignment_height * 16 || - alignment_width != expected_alignment_width || - alignment_height != expected_alignment_height || - rejection_width != expected_rejection_width || - rejection_height != expected_rejection_height || mgc_pattern == 0 || - !std::isfinite(overall_gain) || overall_gain <= 0.0f || - !std::isfinite(merge_sharpness) || merge_sharpness < 0.0f) { - return -1; - } - - int64_t raw_pixel_count = 0; - int64_t output_sample_count = 0; - int64_t alignment_sample_count = 0; - int64_t rejection_sample_count = 0; - if (!CheckedProduct({raw_width, raw_height}, &raw_pixel_count) || - !CheckedProduct( - {output_storage_width, output_storage_height, 3}, - &output_sample_count) || - !CheckedProduct( - {alignment_width, alignment_height, frame_count, 2}, - &alignment_sample_count) || - !CheckedProduct( - {rejection_width, rejection_height, frame_count}, - &rejection_sample_count) || - raw_pixel_count > static_cast( - std::numeric_limits::max() / sizeof(uint16_t))) { - return -1; - } - - auto* alignment = static_cast(env->GetDirectBufferAddress(alignment_buffer)); - auto* rejection = static_cast(env->GetDirectBufferAddress(rejection_buffer)); - auto* output = static_cast(env->GetDirectBufferAddress(output_buffer)); - if (alignment == nullptr || rejection == nullptr || output == nullptr || - env->GetDirectBufferCapacity(alignment_buffer) < - alignment_sample_count * static_cast(sizeof(float)) || - env->GetDirectBufferCapacity(rejection_buffer) < rejection_sample_count || - env->GetDirectBufferCapacity(output_buffer) < - output_sample_count * static_cast(sizeof(uint16_t))) { - return -1; - } - - std::vector raw_offsets(frame_count); - std::vector raw_row_strides(frame_count); - env->GetIntArrayRegion(raw_offsets_array, 0, frame_count, raw_offsets.data()); - env->GetIntArrayRegion( - raw_row_strides_array, - 0, - frame_count, - raw_row_strides.data()); - if (env->ExceptionCheck()) return -1; - - // Camera2 RAW planes are normally tight. Point the AOT directly at those direct buffers and - // allocate a packed copy only for the uncommon padded-row plane; copying the whole burst would - // otherwise duplicate hundreds of megabytes before Halide starts. - std::vector> packed_raw(frame_count); - std::vector burst_ptrs(frame_count); - for (int frame = 0; frame < frame_count; ++frame) { - jobject raw_buffer = env->GetObjectArrayElement(raw_buffers, frame); - if (raw_buffer == nullptr) return -1; - auto* raw_base = static_cast(env->GetDirectBufferAddress(raw_buffer)); - const int64_t raw_capacity = env->GetDirectBufferCapacity(raw_buffer); - const int64_t offset = raw_offsets[frame]; - const int64_t row_stride = raw_row_strides[frame]; - const int64_t required = offset + - static_cast(raw_height - 1) * row_stride + - static_cast(raw_width) * sizeof(uint16_t); - if (raw_base == nullptr || offset < 0 || (offset & 1LL) != 0 || - row_stride < raw_width * 2LL || - required > raw_capacity) { - env->DeleteLocalRef(raw_buffer); - return -1; - } - uint16_t* destination = nullptr; - if (row_stride == raw_width * static_cast(sizeof(uint16_t))) { - destination = reinterpret_cast(raw_base + offset); - } else { - packed_raw[frame].resize(static_cast(raw_pixel_count)); - destination = packed_raw[frame].data(); - for (int y = 0; y < raw_height; ++y) { - std::memcpy( - destination + static_cast(y) * raw_width, - raw_base + offset + static_cast(y) * row_stride, - static_cast(raw_width) * sizeof(uint16_t)); - } - } - burst_ptrs[frame] = reinterpret_cast(destination); - env->DeleteLocalRef(raw_buffer); - } - - std::vector frame_weights; - std::vector wb_gains; - std::vector black_rgb; - std::vector black_rggb; - std::vector input_gains; - std::vector kernel_sigmas; - if (!CopyFloatArray(env, frame_weights_array, frame_count, &frame_weights, true) || - !CopyFloatArray(env, wb_gains_array, 4, &wb_gains, true) || - !CopyFloatArray(env, input_black_levels_rgb_array, 3, &black_rgb, false) || - !CopyFloatArray(env, input_black_levels_rggb_array, 4, &black_rggb, false) || - !CopyFloatArray(env, input_gains_array, frame_count, &input_gains, true) || - !CopyFloatArray(env, kernel_sigmas_array, frame_count, &kernel_sigmas, true)) { - return -1; - } - - const int32_t alignment_plane_stride = alignment_width * alignment_height; - const int32_t rejection_plane_stride = rejection_width * rejection_height; - const int32_t output_plane_stride = output_storage_width * output_storage_height; - const HalideDimension raw_dimensions[2] = { - {0, raw_width, 1, 0}, - {0, raw_height, raw_width, 0}, - }; - const HalideDimension burst_dimensions[1] = {{0, frame_count, 1, 0}}; - const HalideDimension alignment_dimensions[4] = { - {0, alignment_width, 1, 0}, - {0, alignment_height, alignment_width, 0}, - {0, frame_count, alignment_plane_stride, 0}, - {0, 2, alignment_plane_stride * frame_count, 0}, - }; - const HalideDimension rejection_dimensions[3] = { - {0, rejection_width, 1, 0}, - {0, rejection_height, rejection_width, 0}, - {0, frame_count, rejection_plane_stride, 0}, - }; - const HalideDimension frame_dimensions[1] = {{0, frame_count, 1, 0}}; - const HalideDimension wb_dimensions[1] = {{0, 4, 1, 0}}; - const HalideDimension rgb_dimensions[1] = {{0, 3, 1, 0}}; - const HalideDimension rggb_dimensions[1] = {{0, 4, 1, 0}}; - // The generated schedule constrains the output buffer extents to complete 16x16 tiles. Keep - // those storage extents separate from output_width/output_height: the latter are semantic - // parameters used by MGC's sampling and rejection equations. - const HalideDimension output_dimensions[3] = { - {0, output_storage_width, 1, 0}, - {0, output_storage_height, output_storage_width, 0}, - {0, 3, output_plane_stride, 0}, - }; - - HalideBuffer base = MakeBuffer( - reinterpret_cast(static_cast(burst_ptrs[0])), - kUInt16, - raw_dimensions, - 2); - HalideBuffer burst = MakeBuffer( - burst_ptrs.data(), kUInt64, burst_dimensions, 1); - HalideBuffer alignment_halide = MakeBuffer( - alignment, kFloat32, alignment_dimensions, 4); - HalideBuffer rejection_halide = MakeBuffer( - rejection, kUInt8, rejection_dimensions, 3); - HalideBuffer weights_halide = MakeBuffer( - frame_weights.data(), kFloat32, frame_dimensions, 1); - HalideBuffer wb_halide = MakeBuffer( - wb_gains.data(), kFloat32, wb_dimensions, 1); - HalideBuffer black_rgb_halide = MakeBuffer( - black_rgb.data(), kFloat32, rgb_dimensions, 1); - HalideBuffer black_rggb_halide = MakeBuffer( - black_rggb.data(), kFloat32, rggb_dimensions, 1); - HalideBuffer gains_halide = MakeBuffer( - input_gains.data(), kFloat32, frame_dimensions, 1); - HalideBuffer sigmas_halide = MakeBuffer( - kernel_sigmas.data(), kFloat32, frame_dimensions, 1); - HalideBuffer output_halide = MakeBuffer( - output, kFloat16, output_dimensions, 3); - - const int result = photon_mgc_merge_rgb_raw16_f16_tile16_halide( - nullptr, - mgc_pattern, - &base, - &burst, - &alignment_halide, - &rejection_halide, - &weights_halide, - &wb_halide, - &black_rgb_halide, - &black_rggb_halide, - &gains_halide, - overall_gain, - merge_sharpness, - &sigmas_halide, - output_width, - output_height, - &output_halide); - if (result != 0) { - __android_log_print( - ANDROID_LOG_ERROR, - kTag, - "MergeRgbRaw16F16 failed result=%d raw=%dx%d logical=%dx%d " - "storage=%dx%d frames=%d cfa=%d", - result, - raw_width, - raw_height, - output_width, - output_height, - output_storage_width, - output_storage_height, - frame_count, - cfa_pattern); - return result; - } - return 0; -} diff --git a/app/src/main/cpp/mgc_denoise_static/mgc_spatial_rgb_merge_static.S.in b/app/src/main/cpp/mgc_denoise_static/mgc_spatial_rgb_merge_static.S.in deleted file mode 100644 index 218b12c6..00000000 --- a/app/src/main/cpp/mgc_denoise_static/mgc_spatial_rgb_merge_static.S.in +++ /dev/null @@ -1,1118 +0,0 @@ -/* Generated mechanically from pinned MGC 9.7.047 V25 Spatial RGB Merge AOT. - * Do not edit; regenerate with - * scripts/research/generate_mgc_spatial_rgb_merge_static_asm.py. - */ - -#if !defined(__aarch64__) -#error "MGC Spatial RGB Merge static lift is arm64-only" -#endif - - .hidden photon_mgc_halide_error_2055170 - .hidden photon_mgc_halide_error_38a3740 - .hidden photon_mgc_halide_error_38a92e8 - .hidden photon_mgc_halide_error_5f94b18 - .hidden photon_mgc_halide_error_5f94c0c - .hidden photon_mgc_halide_error_5f94c78 - .hidden photon_mgc_halide_error_5f94d60 - .hidden photon_mgc_halide_error_5f94e38 - .hidden photon_mgc_halide_error_5f94ec4 - .hidden photon_mgc_halide_error_5f94fa8 - .hidden photon_mgc_halide_error_5f95034 - .hidden photon_mgc_halide_error_5f950cc - .hidden photon_mgc_halide_error_5f95260 - .hidden photon_mgc_halide_error_5f95540 - .hidden photon_mgc_halide_error_5f95560 - .hidden photon_mgc_halide_error_5f95638 - .hidden photon_mgc_halide_error_5f956a4 - .hidden photon_mgc_halide_error_5ff6938 - .hidden photon_mgc_halide_error_5ff8944 - .hidden photon_mgc_halide_error_5ff89a0 - .hidden photon_mgc_halide_do_par_for - .hidden photon_mgc_halide_free - .hidden photon_mgc_halide_malloc - .hidden photon_mgc_halide_trace - .hidden photon_mgc_u16_copy_dispatch - -.section .text.photon_mgc.SpatialRgb.u16_copy_dispatch,"ax",@progbits - .p2align 4 - .type photon_mgc_u16_copy_dispatch, %function -photon_mgc_u16_copy_dispatch: - cmp w0, #2 - b.ne .Lphoton_mgc_u16_copy_unsupported - mov x0, x1 - mov x1, x2 - ldr w8, [x1, #0x24] - cmp w8, #3 - b.eq photon_mgc_spatial_rgb_address_5e4dca8 - b photon_mgc_spatial_rgb_address_5e4cb58 -.Lphoton_mgc_u16_copy_unsupported: - mov w0, #-1 - ret - .size photon_mgc_u16_copy_dispatch, .-photon_mgc_u16_copy_dispatch - -.section .text.photon_mgc.SpatialRgb.merge,"ax",@progbits - .p2align 12 - .global photon_mgc_merge_rgb_raw16_f16_tile16_halide - .hidden photon_mgc_merge_rgb_raw16_f16_tile16_halide - .type photon_mgc_merge_rgb_raw16_f16_tile16_halide, %function -photon_mgc_spatial_rgb_page_370f000: - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0x0, 0x514 -photon_mgc_spatial_rgb_address_370f514: - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0x514, 0x38 - adrp x10, photon_mgc_spatial_rgb_page_6b6000 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0x54c, 0x38 - adrp x10, photon_mgc_spatial_rgb_page_6bc000 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0x584, 0x70 - adrp x8, photon_mgc_spatial_rgb_page_6b4000 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0x5f4, 0x2ec - bl photon_mgc_spatial_rgb_address_389b420 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0x8e0, 0x274 - bl photon_mgc_spatial_rgb_address_389b420 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0xb54, 0x214 - adrp x20, photon_mgc_spatial_rgb_page_6ba000 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0xd68, 0xf0 - adrp x15, photon_mgc_spatial_rgb_page_6bc000 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0xe58, 0x18c -photon_mgc_spatial_rgb_page_3710000: - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0xfe4, 0x80 - adrp x9, photon_mgc_spatial_rgb_page_6c2000 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0x1064, 0x8 - adrp x9, photon_mgc_spatial_rgb_page_6b9000 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0x106c, 0x4 - adrp x9, photon_mgc_spatial_rgb_page_6b5000 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0x1070, 0xf68 -photon_mgc_spatial_rgb_page_3711000: - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0x1fd8, 0xb8 - bl photon_mgc_spatial_rgb_address_389b420 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0x2090, 0x278 - bl photon_mgc_spatial_rgb_address_389b420 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0x2308, 0x1c4 - bl photon_mgc_spatial_rgb_address_389b420 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0x24cc, 0x2a0 - bl photon_mgc_spatial_rgb_address_389b420 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0x276c, 0x1f8 - bl photon_mgc_spatial_rgb_address_389b420 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0x2964, 0x3c - adrp x4, photon_mgc_spatial_rgb_page_6bc000 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0x29a0, 0x620 -photon_mgc_spatial_rgb_page_3712000: - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0x2fc0, 0xd74 - adrp x8, photon_mgc_spatial_rgb_page_6c4000 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0x3d34, 0x288 -photon_mgc_spatial_rgb_page_3713000: - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0x3fbc, 0x470 - bl photon_mgc_halide_free - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0x442c, 0x2c - bl photon_mgc_halide_malloc - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0x4458, 0x58 - bl photon_mgc_halide_free - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0x44b0, 0x44 - bl photon_mgc_halide_malloc - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0x44f4, 0x40 - bl photon_mgc_halide_free - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0x4534, 0x20 - adrp x4, photon_mgc_spatial_rgb_page_6bc000 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0x4554, 0x20 - bl photon_mgc_halide_malloc - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0x4574, 0x20 - adrp x4, photon_mgc_spatial_rgb_page_6bc000 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0x4594, 0x69c - bl photon_mgc_spatial_rgb_address_389b420 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0x4c30, 0x288 - bl photon_mgc_spatial_rgb_address_389b420 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0x4eb8, 0xdc -photon_mgc_spatial_rgb_page_3714000: - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0x4f94, 0x104 - bl photon_mgc_spatial_rgb_address_389b420 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0x5098, 0x298 - bl photon_mgc_spatial_rgb_address_389b420 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0x5330, 0x1f4 - bl photon_mgc_spatial_rgb_address_389b420 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0x5524, 0x3c - adrp x30, photon_mgc_spatial_rgb_page_6bc000 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0x5560, 0x50c - adrp x30, photon_mgc_spatial_rgb_page_6bc000 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0x5a6c, 0x2dc - adrp x30, photon_mgc_spatial_rgb_page_6bc000 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0x5d48, 0x234 -photon_mgc_spatial_rgb_page_3715000: - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0x5f7c, 0x1000 -photon_mgc_spatial_rgb_page_3716000: - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0x6f7c, 0x74 - adrp x8, photon_mgc_spatial_rgb_page_6c4000 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0x6ff0, 0x6dc - bl photon_mgc_halide_free - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0x76cc, 0x2c - bl photon_mgc_halide_malloc - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0x76f8, 0x4c - bl photon_mgc_halide_free - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0x7744, 0x34 - bl photon_mgc_halide_malloc - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0x7778, 0x34 - bl photon_mgc_halide_free - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0x77ac, 0x18 - adrp x30, photon_mgc_spatial_rgb_page_6bc000 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0x77c4, 0x20 - bl photon_mgc_halide_malloc - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0x77e4, 0x18 - adrp x30, photon_mgc_spatial_rgb_page_6bc000 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0x77fc, 0x618 - bl photon_mgc_spatial_rgb_address_389b420 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0x7e14, 0x140 -photon_mgc_spatial_rgb_page_3717000: - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0x7f54, 0x154 - bl photon_mgc_spatial_rgb_address_389b420 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0x80a8, 0x1e4 - bl photon_mgc_spatial_rgb_address_389b420 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0x828c, 0x2a0 - bl photon_mgc_spatial_rgb_address_389b420 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0x852c, 0x1f4 - bl photon_mgc_spatial_rgb_address_389b420 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0x8720, 0x3c - adrp x4, photon_mgc_spatial_rgb_page_6bc000 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0x875c, 0x7e4 -photon_mgc_spatial_rgb_page_3718000: - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0x8f40, 0xbcc - adrp x8, photon_mgc_spatial_rgb_page_6c4000 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0x9b0c, 0x430 -photon_mgc_spatial_rgb_page_3719000: - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0x9f3c, 0x3a8 - bl photon_mgc_halide_free - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0xa2e4, 0x2c - bl photon_mgc_halide_malloc - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0xa310, 0x54 - bl photon_mgc_halide_free - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0xa364, 0x34 - bl photon_mgc_halide_malloc - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0xa398, 0x3c - bl photon_mgc_halide_free - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0xa3d4, 0x20 - adrp x4, photon_mgc_spatial_rgb_page_6bc000 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0xa3f4, 0x20 - bl photon_mgc_halide_malloc - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0xa414, 0x20 - adrp x4, photon_mgc_spatial_rgb_page_6bc000 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0xa434, 0x10c - bl photon_mgc_halide_free - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0xa540, 0x28 - bl photon_mgc_halide_free - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0xa568, 0x28 - bl photon_mgc_halide_free - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0xa590, 0x14 - bl photon_mgc_halide_free - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0xa5a4, 0x48 - bl photon_mgc_halide_malloc - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0xa5ec, 0x24 - adrp x1, photon_mgc_spatial_rgb_page_bc6000 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0xa610, 0x4 - bl photon_mgc_halide_error_5f94b18 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0xa614, 0xc - adrp x1, photon_mgc_spatial_rgb_page_bc6000 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0xa620, 0x8 - bl photon_mgc_halide_error_5f94b18 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0xa628, 0x10 - adrp x1, photon_mgc_spatial_rgb_page_bc6000 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0xa638, 0x4 - bl photon_mgc_halide_error_5f94c0c - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0xa63c, 0x3c - adrp x1, photon_mgc_spatial_rgb_page_bc6000 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0xa678, 0x4 - bl photon_mgc_halide_error_5f94b18 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0xa67c, 0x1c - adrp x1, photon_mgc_spatial_rgb_page_bc6000 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0xa698, 0xc - bl photon_mgc_halide_error_5f94fa8 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0xa6a4, 0x30 - adrp x1, photon_mgc_spatial_rgb_page_bc6000 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0xa6d4, 0xc - bl photon_mgc_halide_error_5f94fa8 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0xa6e0, 0x18 - adrp x1, photon_mgc_spatial_rgb_page_bc6000 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0xa6f8, 0x8 - bl photon_mgc_halide_error_5f94fa8 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0xa700, 0x20 - adrp x1, photon_mgc_spatial_rgb_page_bc6000 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0xa720, 0x8 - bl photon_mgc_halide_error_5f94fa8 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0xa728, 0x1c - adrp x1, photon_mgc_spatial_rgb_page_bc6000 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0xa744, 0x4 - bl photon_mgc_halide_error_5f94b18 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0xa748, 0xc - adrp x1, photon_mgc_spatial_rgb_page_bc6000 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0xa754, 0x18 - bl photon_mgc_halide_error_5f94fa8 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0xa76c, 0x58 -photon_mgc_spatial_rgb_address_371990c: -photon_mgc_merge_rgb_raw16_f16_tile16_halide: - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0xa7c4, 0x168 - adrp x1, photon_mgc_spatial_rgb_page_bc6000 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0xa92c, 0x20 - adrp x1, photon_mgc_spatial_rgb_page_bc6000 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0xa94c, 0x20 - adrp x1, photon_mgc_spatial_rgb_page_bc6000 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0xa96c, 0x518 - bl photon_mgc_spatial_rgb_address_389ec70 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0xae84, 0x24 -photon_mgc_spatial_rgb_page_371a000: - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0xaea8, 0x218 - bl photon_mgc_spatial_rgb_address_389ec70 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0xb0c0, 0x8 - adrp x9, photon_mgc_spatial_rgb_page_6b6000 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0xb0c8, 0x1c - adrp x10, photon_mgc_spatial_rgb_page_6bc000 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0xb0e4, 0x198 - bl photon_mgc_spatial_rgb_address_389b420 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0xb27c, 0x1a0 - bl photon_mgc_spatial_rgb_address_389b420 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0xb41c, 0x2e0 - adrp x13, photon_mgc_spatial_rgb_page_6b4000 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0xb6fc, 0x48 - adrp x9, photon_mgc_spatial_rgb_page_6b4000 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0xb744, 0xf8 - adrp x13, photon_mgc_spatial_rgb_page_6b4000 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0xb83c, 0x38 - adrp x13, photon_mgc_spatial_rgb_page_6b4000 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0xb874, 0x5c - adrp x15, photon_mgc_spatial_rgb_page_6b4000 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0xb8d0, 0x38 - adrp x14, photon_mgc_spatial_rgb_page_6b4000 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0xb908, 0x88 - adrp x29, photon_mgc_spatial_rgb_page_6b4000 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0xb990, 0x88 - adrp x17, photon_mgc_spatial_rgb_page_6b4000 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0xba18, 0x80 - adrp x29, photon_mgc_spatial_rgb_page_6b4000 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0xba98, 0x10c - adrp x11, photon_mgc_spatial_rgb_page_6b4000 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0xbba4, 0x2c8 -photon_mgc_spatial_rgb_page_371b000: - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0xbe6c, 0x5ac - adrp x1, photon_mgc_spatial_rgb_page_bc6000 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0xc418, 0x8 - bl photon_mgc_halide_error_5f94d60 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0xc420, 0x3c - adrp x1, photon_mgc_spatial_rgb_page_bc6000 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0xc45c, 0x50 - adrp x1, photon_mgc_spatial_rgb_page_bc6000 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0xc4ac, 0x8 - bl photon_mgc_halide_error_5f94d60 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0xc4b4, 0x40 - adrp x1, photon_mgc_spatial_rgb_page_bc6000 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0xc4f4, 0x34 - adrp x1, photon_mgc_spatial_rgb_page_bc6000 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0xc528, 0x30 - adrp x1, photon_mgc_spatial_rgb_page_bc6000 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0xc558, 0x44 - adrp x1, photon_mgc_spatial_rgb_page_bc6000 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0xc59c, 0x44 - adrp x1, photon_mgc_spatial_rgb_page_bc6000 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0xc5e0, 0x2c - adrp x1, photon_mgc_spatial_rgb_page_bc6000 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0xc60c, 0x8 - bl photon_mgc_halide_error_5f94d60 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0xc614, 0x24 - adrp x1, photon_mgc_spatial_rgb_page_bc6000 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0xc638, 0x3c - adrp x1, photon_mgc_spatial_rgb_page_bc6000 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0xc674, 0x48 - adrp x1, photon_mgc_spatial_rgb_page_bc6000 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0xc6bc, 0x30 - adrp x1, photon_mgc_spatial_rgb_page_bc6000 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0xc6ec, 0x30 - adrp x1, photon_mgc_spatial_rgb_page_bc6000 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0xc71c, 0x30 - adrp x1, photon_mgc_spatial_rgb_page_bc6000 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0xc74c, 0x34 - adrp x1, photon_mgc_spatial_rgb_page_bc6000 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0xc780, 0x4 - adrp x3, photon_mgc_spatial_rgb_page_bc6000 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0xc784, 0x24 - adrp x1, photon_mgc_spatial_rgb_page_bc6000 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0xc7a8, 0x34 - adrp x1, photon_mgc_spatial_rgb_page_bc6000 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0xc7dc, 0x20 - adrp x1, photon_mgc_spatial_rgb_page_bc6000 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0xc7fc, 0x2c - adrp x1, photon_mgc_spatial_rgb_page_bc6000 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0xc828, 0x24 - adrp x1, photon_mgc_spatial_rgb_page_bc6000 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0xc84c, 0x30 - adrp x1, photon_mgc_spatial_rgb_page_bc6000 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0xc87c, 0x30 - adrp x1, photon_mgc_spatial_rgb_page_bc6000 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0xc8ac, 0x4 - adrp x3, photon_mgc_spatial_rgb_page_bc6000 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0xc8b0, 0x24 - adrp x1, photon_mgc_spatial_rgb_page_bc6000 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0xc8d4, 0x20 - adrp x1, photon_mgc_spatial_rgb_page_bc6000 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0xc8f4, 0x34 - adrp x1, photon_mgc_spatial_rgb_page_bc6000 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0xc928, 0x44 - adrp x1, photon_mgc_spatial_rgb_page_bc6000 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0xc96c, 0x2c - adrp x1, photon_mgc_spatial_rgb_page_bc6000 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0xc998, 0x8 - bl photon_mgc_halide_error_5f94d60 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0xc9a0, 0x1c - adrp x1, photon_mgc_spatial_rgb_page_bc6000 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0xc9bc, 0x34 - adrp x1, photon_mgc_spatial_rgb_page_bc6000 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0xc9f0, 0x18 - bl photon_mgc_halide_error_5f94ec4 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0xca08, 0xb0 - adrp x1, photon_mgc_spatial_rgb_page_bc6000 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0xcab8, 0x4 - adrp x3, photon_mgc_spatial_rgb_page_bc6000 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0xcabc, 0x8 - bl photon_mgc_halide_error_5f95260 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0xcac4, 0x308 -photon_mgc_spatial_rgb_page_371c000: - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0xcdcc, 0x210 - adrp x1, photon_mgc_spatial_rgb_page_bc6000 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0xcfdc, 0x34 - adrp x1, photon_mgc_spatial_rgb_page_bc6000 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0xd010, 0x2c - adrp x1, photon_mgc_spatial_rgb_page_bc6000 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0xd03c, 0x30 - adrp x1, photon_mgc_spatial_rgb_page_bc6000 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0xd06c, 0x24 - adrp x1, photon_mgc_spatial_rgb_page_bc6000 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0xd090, 0x20 - adrp x1, photon_mgc_spatial_rgb_page_bc6000 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0xd0b0, 0x28 - adrp x1, photon_mgc_spatial_rgb_page_bc6000 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0xd0d8, 0x30 - adrp x1, photon_mgc_spatial_rgb_page_bc6000 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0xd108, 0x24 - adrp x1, photon_mgc_spatial_rgb_page_bc6000 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0xd12c, 0x20 - adrp x1, photon_mgc_spatial_rgb_page_bc6000 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0xd14c, 0x20 - adrp x1, photon_mgc_spatial_rgb_page_bc6000 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0xd16c, 0x28 - adrp x1, photon_mgc_spatial_rgb_page_bc6000 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0xd194, 0x24 - adrp x1, photon_mgc_spatial_rgb_page_bc6000 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0xd1b8, 0x20 - adrp x1, photon_mgc_spatial_rgb_page_bc6000 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0xd1d8, 0x20 - adrp x1, photon_mgc_spatial_rgb_page_bc6000 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0xd1f8, 0x44 - adrp x1, photon_mgc_spatial_rgb_page_bc6000 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0xd23c, 0x1c - adrp x8, photon_mgc_spatial_rgb_page_bc6000 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0xd258, 0x2c - bl photon_mgc_halide_trace - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0xd284, 0xf8 - bl photon_mgc_halide_malloc - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0xd37c, 0x20 - adrp x9, photon_mgc_spatial_rgb_page_6b4000 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0xd39c, 0x94 - bl photon_mgc_spatial_rgb_address_389ec70 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0xd430, 0x274 - adrp x1, photon_mgc_spatial_rgb_page_61e7000 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0xd6a4, 0x4c - bl photon_mgc_halide_do_par_for - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0xd6f0, 0x8 - adrp x20, photon_mgc_spatial_rgb_page_bc6000 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0xd6f8, 0x10 - bl photon_mgc_halide_free - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0xd708, 0x10 - adrp x1, photon_mgc_spatial_rgb_page_bc6000 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0xd718, 0x20 - bl photon_mgc_halide_trace - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0xd738, 0x38 - adrp x1, photon_mgc_spatial_rgb_page_bc6000 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0xd770, 0xc - adrp x1, photon_mgc_spatial_rgb_page_bc6000 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0xd77c, 0x8 - bl photon_mgc_halide_error_5f94b18 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0xd784, 0xc - adrp x1, photon_mgc_spatial_rgb_page_bc6000 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0xd790, 0x4 - adrp x2, photon_mgc_spatial_rgb_page_bc6000 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0xd794, 0x10 - bl photon_mgc_halide_error_5f94c78 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0xd7a4, 0x8 - adrp x1, photon_mgc_spatial_rgb_page_bc6000 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0xd7ac, 0xc - bl photon_mgc_halide_error_5f94fa8 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0xd7b8, 0x8 - bl photon_mgc_halide_error_5f95540 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0xd7c0, 0x8 - adrp x1, photon_mgc_spatial_rgb_page_bc6000 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0xd7c8, 0x8 - bl photon_mgc_halide_error_5f94c0c - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0xd7d0, 0x20 - bl photon_mgc_halide_free - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0xd7f0, 0x8 - adrp x1, photon_mgc_spatial_rgb_page_bc6000 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0xd7f8, 0x8 - adrp x1, photon_mgc_spatial_rgb_page_bc6000 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0xd800, 0x8 - adrp x1, photon_mgc_spatial_rgb_page_bc6000 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0xd808, 0x8 - adrp x1, photon_mgc_spatial_rgb_page_bc6000 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0xd810, 0x8 - adrp x1, photon_mgc_spatial_rgb_page_bc6000 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0xd818, 0x8 - adrp x1, photon_mgc_spatial_rgb_page_bc6000 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0xd820, 0x8 - adrp x1, photon_mgc_spatial_rgb_page_bc6000 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0xd828, 0x34 - b photon_mgc_halide_error_5f95560 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0xd85c, 0x8 - adrp x1, photon_mgc_spatial_rgb_page_bc6000 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0xd864, 0x10 - adrp x1, photon_mgc_spatial_rgb_page_bc6000 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0xd874, 0x4 - adrp x3, photon_mgc_spatial_rgb_page_bc6000 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0xd878, 0x8 - bl photon_mgc_halide_error_5f95260 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0xd880, 0xc - adrp x1, photon_mgc_spatial_rgb_page_bc6000 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0xd88c, 0x10 - adrp x1, photon_mgc_spatial_rgb_page_bc6000 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0xd89c, 0x4 - adrp x3, photon_mgc_spatial_rgb_page_bc6000 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0xd8a0, 0x8 - bl photon_mgc_halide_error_5f95260 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0xd8a8, 0xc - adrp x1, photon_mgc_spatial_rgb_page_bc6000 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0xd8b4, 0xc - bl photon_mgc_halide_error_5f94d60 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0xd8c0, 0xc - adrp x1, photon_mgc_spatial_rgb_page_bc6000 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0xd8cc, 0x8 - bl photon_mgc_halide_error_5f94e38 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0xd8d4, 0x4 - adrp x1, photon_mgc_spatial_rgb_page_bc6000 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0xd8d8, 0x10 - adrp x1, photon_mgc_spatial_rgb_page_bc6000 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0xd8e8, 0x10 - adrp x1, photon_mgc_spatial_rgb_page_bc6000 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0xd8f8, 0x10 - adrp x1, photon_mgc_spatial_rgb_page_bc6000 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0xd908, 0xc - adrp x1, photon_mgc_spatial_rgb_page_bc6000 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0xd914, 0x8 - adrp x1, photon_mgc_spatial_rgb_page_bc6000 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0xd91c, 0x8 - adrp x1, photon_mgc_spatial_rgb_page_bc6000 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0xd924, 0x14 - adrp x1, photon_mgc_spatial_rgb_page_bc6000 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0xd938, 0x8 - adrp x1, photon_mgc_spatial_rgb_page_bc6000 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0xd940, 0x8 - adrp x1, photon_mgc_spatial_rgb_page_bc6000 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0xd948, 0xc - adrp x1, photon_mgc_spatial_rgb_page_bc6000 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0xd954, 0xc - adrp x1, photon_mgc_spatial_rgb_page_bc6000 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0xd960, 0x8 - adrp x1, photon_mgc_spatial_rgb_page_bc6000 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0xd968, 0xc - adrp x1, photon_mgc_spatial_rgb_page_bc6000 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0xd974, 0xc - adrp x1, photon_mgc_spatial_rgb_page_bc6000 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0xd980, 0x10 - adrp x1, photon_mgc_spatial_rgb_page_bc6000 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0xd990, 0x10 - adrp x1, photon_mgc_spatial_rgb_page_bc6000 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0xd9a0, 0x8 - adrp x1, photon_mgc_spatial_rgb_page_bc6000 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0xd9a8, 0xc - adrp x1, photon_mgc_spatial_rgb_page_bc6000 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0xd9b4, 0xc - adrp x1, photon_mgc_spatial_rgb_page_bc6000 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0xd9c0, 0x8 - adrp x1, photon_mgc_spatial_rgb_page_bc6000 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0xd9c8, 0x8 - adrp x1, photon_mgc_spatial_rgb_page_bc6000 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0xd9d0, 0x8 - bl photon_mgc_halide_error_5f95638 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0xd9d8, 0x4 - adrp x1, photon_mgc_spatial_rgb_page_bc6000 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0xd9dc, 0xc - adrp x1, photon_mgc_spatial_rgb_page_bc6000 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0xd9e8, 0x10 - bl photon_mgc_halide_error_5f950cc - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0xd9f8, 0x4 - adrp x1, photon_mgc_spatial_rgb_page_bc6000 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0xd9fc, 0x8 - adrp x1, photon_mgc_spatial_rgb_page_bc6000 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0xda04, 0x8 - adrp x1, photon_mgc_spatial_rgb_page_bc6000 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0xda0c, 0x8 - bl photon_mgc_halide_error_5f956a4 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0xda14, 0x8 - adrp x1, photon_mgc_spatial_rgb_page_bc6000 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0xda1c, 0xc - bl photon_mgc_halide_error_5f95034 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0xda28, 0xc - adrp x1, photon_mgc_spatial_rgb_page_bc6000 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0xda34, 0xc - adrp x1, photon_mgc_spatial_rgb_page_bc6000 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0xda40, 0xc - bl photon_mgc_halide_error_5f95034 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0xda4c, 0xc - adrp x1, photon_mgc_spatial_rgb_page_bc6000 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0xda58, 0xc - adrp x1, photon_mgc_spatial_rgb_page_bc6000 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0xda64, 0xc - bl photon_mgc_halide_error_5f95034 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0xda70, 0x8 - adrp x1, photon_mgc_spatial_rgb_page_bc6000 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0xda78, 0xc - bl photon_mgc_halide_error_5f95034 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0xda84, 0x8 - adrp x1, photon_mgc_spatial_rgb_page_bc6000 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0xda8c, 0xc - bl photon_mgc_halide_error_5f95034 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0xda98, 0xc - adrp x1, photon_mgc_spatial_rgb_page_bc6000 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0xdaa4, 0x8 - bl photon_mgc_halide_error_5f94e38 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0xdaac, 0x8 - adrp x1, photon_mgc_spatial_rgb_page_bc6000 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0xdab4, 0xc - bl photon_mgc_halide_error_5f95034 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0xdac0, 0xc - adrp x1, photon_mgc_spatial_rgb_page_bc6000 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0xdacc, 0xc - adrp x1, photon_mgc_spatial_rgb_page_bc6000 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0xdad8, 0xc - bl photon_mgc_halide_error_5f95034 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0xdae4, 0xc - adrp x1, photon_mgc_spatial_rgb_page_bc6000 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0xdaf0, 0xc - adrp x1, photon_mgc_spatial_rgb_page_bc6000 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0xdafc, 0xc - bl photon_mgc_halide_error_5f95034 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0xdb08, 0x8 - adrp x1, photon_mgc_spatial_rgb_page_bc6000 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0xdb10, 0xc - bl photon_mgc_halide_error_5f95034 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0xdb1c, 0x8 - adrp x1, photon_mgc_spatial_rgb_page_bc6000 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0xdb24, 0x4 - adrp x3, photon_mgc_spatial_rgb_page_bc6000 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0xdb28, 0x10 - adrp x1, photon_mgc_spatial_rgb_page_bc6000 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0xdb38, 0xc - bl photon_mgc_halide_error_5f95034 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0xdb44, 0xc - adrp x1, photon_mgc_spatial_rgb_page_bc6000 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0xdb50, 0x8 - bl photon_mgc_halide_error_5f94e38 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0xdb58, 0x8 - adrp x1, photon_mgc_spatial_rgb_page_bc6000 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0xdb60, 0xc - bl photon_mgc_halide_error_5f95034 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0xdb6c, 0xc - adrp x1, photon_mgc_spatial_rgb_page_bc6000 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0xdb78, 0xc - adrp x1, photon_mgc_spatial_rgb_page_bc6000 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0xdb84, 0xc - bl photon_mgc_halide_error_5f95034 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0xdb90, 0x8 - adrp x1, photon_mgc_spatial_rgb_page_bc6000 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0xdb98, 0xc - bl photon_mgc_halide_error_5f95034 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0xdba4, 0x8 - adrp x1, photon_mgc_spatial_rgb_page_bc6000 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0xdbac, 0x4 - adrp x3, photon_mgc_spatial_rgb_page_bc6000 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0xdbb0, 0x14 - adrp x1, photon_mgc_spatial_rgb_page_bc6000 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0xdbc4, 0x4 -photon_mgc_spatial_rgb_page_371d000: - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0xdbc8, 0x8 - adrp x1, photon_mgc_spatial_rgb_page_bc6000 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0xdbd0, 0xc - bl photon_mgc_halide_error_5f95034 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0xdbdc, 0x8 - adrp x1, photon_mgc_spatial_rgb_page_bc6000 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0xdbe4, 0xc - bl photon_mgc_halide_error_5f95034 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0xdbf0, 0x8 - adrp x1, photon_mgc_spatial_rgb_page_bc6000 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0xdbf8, 0xc - bl photon_mgc_halide_error_5f95034 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0xdc04, 0xc - adrp x1, photon_mgc_spatial_rgb_page_bc6000 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0xdc10, 0x8 - bl photon_mgc_halide_error_5f94e38 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0xdc18, 0xc - adrp x1, photon_mgc_spatial_rgb_page_bc6000 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0xdc24, 0x8 - bl photon_mgc_halide_error_5f95034 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0xdc2c, 0x8 - adrp x1, photon_mgc_spatial_rgb_page_bc6000 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0xdc34, 0xc - bl photon_mgc_halide_error_5f95034 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0xdc40, 0x8 - adrp x1, photon_mgc_spatial_rgb_page_bc6000 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0xdc48, 0x4 - adrp x3, photon_mgc_spatial_rgb_page_bc6000 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0xdc4c, 0x10 - adrp x1, photon_mgc_spatial_rgb_page_bc6000 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0xdc5c, 0x4 - adrp x3, photon_mgc_spatial_rgb_page_bc6000 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0xdc60, 0xf28 - - -.section .text.photon_mgc.SpatialRgb.green_dispatch,"ax",@progbits - .p2align 12 -photon_mgc_spatial_rgb_page_389e000: - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0xeb88, 0xc70 -photon_mgc_spatial_rgb_address_389ec70: - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0xf7f8, 0x84 - adrp x10, photon_mgc_spatial_rgb_page_6b2000 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0xf87c, 0x19c - bl photon_mgc_halide_error_38a92e8 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0xfa18, 0x14 - bl photon_mgc_halide_error_38a3740 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0xfa2c, 0x1c - bl photon_mgc_spatial_rgb_address_38aee1c - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0xfa48, 0x14 - adrp x2, photon_mgc_spatial_rgb_page_4e9000 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0xfa5c, 0x8 - bl photon_mgc_halide_error_5ff6938 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0xfa64, 0x8 - bl photon_mgc_halide_error_2055170 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0xfa6c, 0x4 - adrp x1, photon_mgc_spatial_rgb_page_51d000 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0xfa70, 0x10 - adrp x1, photon_mgc_spatial_rgb_page_51d000 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0xfa80, 0x4 - adrp x3, photon_mgc_spatial_rgb_page_53d000 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0xfa84, 0x10 - bl photon_mgc_halide_error_5ff8944 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0xfa94, 0x4 - bl photon_mgc_halide_error_5ff89a0 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0xfa98, 0xc0 - - -.section .text.photon_mgc.SpatialRgb.green_raw16,"ax",@progbits - .p2align 12 -photon_mgc_spatial_rgb_page_38aa000: - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0xfb58, 0x69c -photon_mgc_spatial_rgb_address_38aa69c: - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0x101f4, 0x1cc - bl photon_mgc_halide_malloc - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0x103c0, 0x44 - bl photon_mgc_halide_malloc - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0x10404, 0x1c - bl photon_mgc_halide_malloc - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0x10420, 0x68c - bl photon_mgc_halide_malloc - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0x10aac, 0x9c -photon_mgc_spatial_rgb_page_38ab000: - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0x10b48, 0xd70 - bl photon_mgc_halide_free - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0x118b8, 0x28c -photon_mgc_spatial_rgb_page_38ac000: - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0x11b44, 0x8 - bl photon_mgc_halide_malloc - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0x11b4c, 0x420 - bl photon_mgc_halide_malloc - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0x11f6c, 0x474 - bl photon_mgc_halide_free - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0x123e0, 0x18 - bl photon_mgc_halide_free - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0x123f8, 0x150 - bl photon_mgc_halide_free - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0x12548, 0x78 - bl photon_mgc_halide_malloc - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0x125c0, 0xc8 - bl photon_mgc_halide_malloc - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0x12688, 0x68 - bl photon_mgc_halide_error_5f95540 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0x126f0, 0x58 - bl photon_mgc_halide_malloc - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0x12748, 0x4c - bl photon_mgc_halide_malloc - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0x12794, 0x1c - bl photon_mgc_halide_malloc - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0x127b0, 0x368 -photon_mgc_spatial_rgb_page_38ad000: - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0x12b18, 0x20c - bl photon_mgc_halide_malloc - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0x12d24, 0x6e4 - bl photon_mgc_halide_free - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0x13408, 0x288 - bl photon_mgc_halide_malloc - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0x13690, 0x424 - bl photon_mgc_halide_malloc - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0x13ab4, 0x54 -photon_mgc_spatial_rgb_page_38ae000: - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0x13b08, 0x420 - bl photon_mgc_halide_free - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0x13f28, 0x18 - bl photon_mgc_halide_free - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0x13f40, 0x118 - bl photon_mgc_halide_free - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0x14058, 0x68 - bl photon_mgc_halide_malloc - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0x140c0, 0xa0 - bl photon_mgc_halide_malloc - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0x14160, 0x48 - bl photon_mgc_halide_free - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0x141a8, 0x14 - bl photon_mgc_halide_free - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0x141bc, 0x14 - bl photon_mgc_halide_free - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0x141d0, 0x30 - adrp x1, photon_mgc_spatial_rgb_page_bd1000 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0x14200, 0xc - bl photon_mgc_halide_error_5f94fa8 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0x1420c, 0xc - adrp x1, photon_mgc_spatial_rgb_page_bd1000 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0x14218, 0xc - bl photon_mgc_halide_error_5f94fa8 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0x14224, 0x8 - adrp x1, photon_mgc_spatial_rgb_page_bd1000 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0x1422c, 0x20 - bl photon_mgc_halide_error_5f94fa8 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0x1424c, 0x2c - adrp x1, photon_mgc_spatial_rgb_page_bd1000 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0x14278, 0x28 - bl photon_mgc_halide_error_5f94fa8 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0x142a0, 0x8 - adrp x1, photon_mgc_spatial_rgb_page_bd1000 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0x142a8, 0x20 - bl photon_mgc_halide_error_5f94fa8 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0x142c8, 0x2c - adrp x1, photon_mgc_spatial_rgb_page_bd1000 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0x142f4, 0x28 - bl photon_mgc_halide_error_5f94fa8 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0x1431c, 0xc - bl photon_mgc_halide_error_5f95540 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0x14328, 0x38 - bl photon_mgc_halide_error_5f95540 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0x14360, 0x3c - bl photon_mgc_halide_error_5f95540 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0x1439c, 0x40 - bl photon_mgc_halide_error_5f95540 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0x143dc, 0x3c - bl photon_mgc_halide_error_5f95540 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0x14418, 0x30 - bl photon_mgc_halide_free - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0x14448, 0x68 - adrp x1, photon_mgc_spatial_rgb_page_bd1000 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0x144b0, 0x18 - bl photon_mgc_halide_error_5f94fa8 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0x144c8, 0x8 - adrp x1, photon_mgc_spatial_rgb_page_bd1000 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0x144d0, 0x10 - bl photon_mgc_halide_error_5f94fa8 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0x144e0, 0xc - bl photon_mgc_halide_error_5f95540 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0x144ec, 0x2c - adrp x1, photon_mgc_spatial_rgb_page_bd1000 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0x14518, 0x10 - bl photon_mgc_halide_error_5f94fa8 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0x14528, 0x30 - bl photon_mgc_halide_free - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0x14558, 0x18 - bl photon_mgc_halide_free - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0x14570, 0x14 - bl photon_mgc_halide_free - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0x14584, 0x50 - bl photon_mgc_halide_free - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0x145d4, 0x80 - bl photon_mgc_halide_free - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0x14654, 0x48 - bl photon_mgc_halide_free - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0x1469c, 0x30 - bl photon_mgc_halide_free - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0x146cc, 0x2c - bl photon_mgc_halide_free - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0x146f8, 0x2c - bl photon_mgc_halide_free - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0x14724, 0x30 - bl photon_mgc_halide_free - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0x14754, 0x20 - bl photon_mgc_halide_free - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0x14774, 0x20 - bl photon_mgc_halide_error_5f95540 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0x14794, 0x34 - bl photon_mgc_halide_error_5f95540 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0x147c8, 0x38 - bl photon_mgc_halide_error_5f95540 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0x14800, 0x34 - bl photon_mgc_halide_error_5f95540 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0x14834, 0x30 -photon_mgc_spatial_rgb_address_38aee1c: - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0x14864, 0xb8 - adrp x1, photon_mgc_spatial_rgb_page_bd1000 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0x1491c, 0x128 -photon_mgc_spatial_rgb_page_38af000: - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0x14a44, 0x290 - adrp x7, photon_mgc_spatial_rgb_page_6b4000 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0x14cd4, 0x64 - adrp x14, photon_mgc_spatial_rgb_page_6ba000 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0x14d38, 0x40 - adrp x14, photon_mgc_spatial_rgb_page_6ba000 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0x14d78, 0xa0 - adrp x5, photon_mgc_spatial_rgb_page_6b4000 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0x14e18, 0x3fc - adrp x1, photon_mgc_spatial_rgb_page_bd1000 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0x15214, 0x40 - adrp x1, photon_mgc_spatial_rgb_page_bd1000 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0x15254, 0x3c - adrp x1, photon_mgc_spatial_rgb_page_bd1000 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0x15290, 0x44 - adrp x1, photon_mgc_spatial_rgb_page_bd1000 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0x152d4, 0x4 - adrp x3, photon_mgc_spatial_rgb_page_bd1000 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0x152d8, 0x2c - adrp x1, photon_mgc_spatial_rgb_page_bd1000 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0x15304, 0x2c - adrp x1, photon_mgc_spatial_rgb_page_bd1000 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0x15330, 0x3c - adrp x1, photon_mgc_spatial_rgb_page_bd1000 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0x1536c, 0x30 - adrp x1, photon_mgc_spatial_rgb_page_bd1000 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0x1539c, 0x4 - adrp x3, photon_mgc_spatial_rgb_page_bd1000 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0x153a0, 0x2c - adrp x1, photon_mgc_spatial_rgb_page_bd1000 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0x153cc, 0x1d8 - adrp x1, photon_mgc_spatial_rgb_page_bd1000 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0x155a4, 0x34 - adrp x1, photon_mgc_spatial_rgb_page_bd1000 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0x155d8, 0x20 - adrp x1, photon_mgc_spatial_rgb_page_bd1000 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0x155f8, 0x24 - adrp x1, photon_mgc_spatial_rgb_page_bd1000 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0x1561c, 0x18 - adrp x1, photon_mgc_spatial_rgb_page_bd1000 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0x15634, 0x1c - adrp x1, photon_mgc_spatial_rgb_page_bd1000 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0x15650, 0x18 - adrp x1, photon_mgc_spatial_rgb_page_bd1000 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0x15668, 0x48 - adrp x1, photon_mgc_spatial_rgb_page_bd1000 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0x156b0, 0x10 - adrp x8, photon_mgc_spatial_rgb_page_bd1000 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0x156c0, 0x24 - bl photon_mgc_halide_trace - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0x156e4, 0x4 - adrp x1, photon_mgc_spatial_rgb_page_61e7000 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0x156e8, 0x114 - adrp x8, photon_mgc_spatial_rgb_page_6c3000 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0x157fc, 0x4 - adrp x8, photon_mgc_spatial_rgb_page_6bd000 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0x15800, 0x34 - bl photon_mgc_halide_do_par_for - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0x15834, 0x4 - adrp x8, photon_mgc_spatial_rgb_page_bd1000 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0x15838, 0x1c - adrp x1, photon_mgc_spatial_rgb_page_bd1000 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0x15854, 0x1c - bl photon_mgc_halide_trace - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0x15870, 0x2c - adrp x1, photon_mgc_spatial_rgb_page_bd1000 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0x1589c, 0x8 - adrp x1, photon_mgc_spatial_rgb_page_bd1000 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0x158a4, 0xc - adrp x1, photon_mgc_spatial_rgb_page_bd1000 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0x158b0, 0x28 - b photon_mgc_halide_error_5f95560 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0x158d8, 0x4 - adrp x1, photon_mgc_spatial_rgb_page_bd1000 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0x158dc, 0x10 - adrp x1, photon_mgc_spatial_rgb_page_bd1000 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0x158ec, 0xc - adrp x1, photon_mgc_spatial_rgb_page_bd1000 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0x158f8, 0x20 - adrp x1, photon_mgc_spatial_rgb_page_bd1000 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0x15918, 0x18 - adrp x1, photon_mgc_spatial_rgb_page_bd1000 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0x15930, 0x14 - adrp x1, photon_mgc_spatial_rgb_page_bd1000 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0x15944, 0x10 - adrp x1, photon_mgc_spatial_rgb_page_bd1000 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0x15954, 0x18 - adrp x1, photon_mgc_spatial_rgb_page_bd1000 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0x1596c, 0x10 - adrp x1, photon_mgc_spatial_rgb_page_bd1000 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0x1597c, 0x14 -photon_mgc_spatial_rgb_page_38b0000: - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0x15990, 0x18 - b photon_mgc_halide_error_5f94e38 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0x159a8, 0xc - adrp x1, photon_mgc_spatial_rgb_page_bd1000 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0x159b4, 0x2c - b photon_mgc_halide_error_5f94d60 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0x159e0, 0x10 - adrp x1, photon_mgc_spatial_rgb_page_bd1000 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0x159f0, 0x30 - b photon_mgc_halide_error_5f94ec4 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0x15a20, 0x4 - adrp x1, photon_mgc_spatial_rgb_page_bd1000 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0x15a24, 0x10 - adrp x1, photon_mgc_spatial_rgb_page_bd1000 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0x15a34, 0xc - adrp x1, photon_mgc_spatial_rgb_page_bd1000 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0x15a40, 0x8 - adrp x1, photon_mgc_spatial_rgb_page_bd1000 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0x15a48, 0xc - adrp x1, photon_mgc_spatial_rgb_page_bd1000 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0x15a54, 0x8 - adrp x1, photon_mgc_spatial_rgb_page_bd1000 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0x15a5c, 0x30 - b photon_mgc_halide_error_5f94fa8 - adrp x1, photon_mgc_spatial_rgb_page_bd1000 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0x15a8c, 0x28 - b photon_mgc_halide_error_5f95638 - adrp x1, photon_mgc_spatial_rgb_page_bd1000 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0x15ab4, 0x30 - b photon_mgc_halide_error_5f950cc - adrp x1, photon_mgc_spatial_rgb_page_bd1000 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0x15ae4, 0x8 - adrp x1, photon_mgc_spatial_rgb_page_bd1000 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0x15aec, 0x28 - b photon_mgc_halide_error_5f956a4 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0x15b14, 0x4 - adrp x1, photon_mgc_spatial_rgb_page_bd1000 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0x15b18, 0x18 - adrp x1, photon_mgc_spatial_rgb_page_bd1000 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0x15b30, 0xc - adrp x1, photon_mgc_spatial_rgb_page_bd1000 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0x15b3c, 0x2c - b photon_mgc_halide_error_5f95034 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0x15b68, 0x8 - adrp x1, photon_mgc_spatial_rgb_page_bd1000 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0x15b70, 0x4 - adrp x3, photon_mgc_spatial_rgb_page_bd1000 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0x15b74, 0x14 - adrp x1, photon_mgc_spatial_rgb_page_bd1000 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0x15b88, 0x4 - adrp x3, photon_mgc_spatial_rgb_page_bd1000 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0x15b8c, 0x2c - b photon_mgc_halide_error_5f95260 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0x15bb8, 0xd68 - - -.section .text.photon_mgc.SpatialRgb.u16_buffer_view_copy,"ax",@progbits - .p2align 12 -photon_mgc_spatial_rgb_page_389b000: - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0x16920, 0x20c - adrp x11, photon_mgc_spatial_rgb_page_6b5000 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0x16b2c, 0x1c0 - bl photon_mgc_u16_copy_dispatch - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0x16cec, 0x4c -photon_mgc_spatial_rgb_address_389b420: - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0x16d38, 0xbe0 - - -.section .text.photon_mgc.SpatialRgb.u16_copy,"ax",@progbits - .p2align 12 -photon_mgc_spatial_rgb_page_5e4c000: - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0x17918, 0xb58 -photon_mgc_spatial_rgb_address_5e4cb58: - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0x18470, 0x4a8 -photon_mgc_spatial_rgb_page_5e4d000: - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0x18918, 0x68 - adrp x6, photon_mgc_spatial_rgb_page_6ba000 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0x18980, 0xc3c -photon_mgc_spatial_rgb_address_5e4dca8: - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0x195bc, 0x358 -photon_mgc_spatial_rgb_page_5e4e000: - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0x19914, 0x1000 - -.section .rodata.photon_mgc.spatial_rgb_page_4e9000,"a",@progbits - .p2align 12 -photon_mgc_spatial_rgb_page_4e9000: - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0x1a914, 0x1000 - -.section .rodata.photon_mgc.spatial_rgb_page_51d000,"a",@progbits - .p2align 12 -photon_mgc_spatial_rgb_page_51d000: - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0x1b914, 0x1000 - -.section .rodata.photon_mgc.spatial_rgb_page_53d000,"a",@progbits - .p2align 12 -photon_mgc_spatial_rgb_page_53d000: - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0x1c914, 0x1000 - -.section .rodata.photon_mgc.spatial_rgb_page_6b2000,"a",@progbits - .p2align 12 -photon_mgc_spatial_rgb_page_6b2000: - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0x1d914, 0x1000 - -.section .rodata.photon_mgc.spatial_rgb_page_6b4000,"a",@progbits - .p2align 12 -photon_mgc_spatial_rgb_page_6b4000: - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0x1e914, 0x1000 - -.section .rodata.photon_mgc.spatial_rgb_page_6b5000,"a",@progbits - .p2align 12 -photon_mgc_spatial_rgb_page_6b5000: - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0x1f914, 0x1000 - -.section .rodata.photon_mgc.spatial_rgb_page_6b6000,"a",@progbits - .p2align 12 -photon_mgc_spatial_rgb_page_6b6000: - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0x20914, 0x1000 - -.section .rodata.photon_mgc.spatial_rgb_page_6b9000,"a",@progbits - .p2align 12 -photon_mgc_spatial_rgb_page_6b9000: - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0x21914, 0x1000 - -.section .rodata.photon_mgc.spatial_rgb_page_6ba000,"a",@progbits - .p2align 12 -photon_mgc_spatial_rgb_page_6ba000: - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0x22914, 0x1000 - -.section .rodata.photon_mgc.spatial_rgb_page_6bc000,"a",@progbits - .p2align 12 -photon_mgc_spatial_rgb_page_6bc000: - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0x23914, 0x1000 - -.section .rodata.photon_mgc.spatial_rgb_page_6bd000,"a",@progbits - .p2align 12 -photon_mgc_spatial_rgb_page_6bd000: - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0x24914, 0x1000 - -.section .rodata.photon_mgc.spatial_rgb_page_6c2000,"a",@progbits - .p2align 12 -photon_mgc_spatial_rgb_page_6c2000: - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0x25914, 0x1000 - -.section .rodata.photon_mgc.spatial_rgb_page_6c3000,"a",@progbits - .p2align 12 -photon_mgc_spatial_rgb_page_6c3000: - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0x26914, 0x1000 - -.section .rodata.photon_mgc.spatial_rgb_page_6c4000,"a",@progbits - .p2align 12 -photon_mgc_spatial_rgb_page_6c4000: - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0x27914, 0x1000 - -.section .rodata.photon_mgc.spatial_rgb_page_bc6000,"a",@progbits - .p2align 12 -photon_mgc_spatial_rgb_page_bc6000: - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0x28914, 0x1000 - -.section .rodata.photon_mgc.spatial_rgb_page_bd1000,"a",@progbits - .p2align 12 -photon_mgc_spatial_rgb_page_bd1000: - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0x29914, 0x1000 - -.section .data.rel.ro.photon_mgc.spatial_rgb_page_61e7000,"aw",@progbits - .p2align 12 -photon_mgc_spatial_rgb_page_61e7000: - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0x2a914, 0x938 - .xword photon_mgc_spatial_rgb_address_370f514 - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0x2b24c, 0xe8 - .xword photon_mgc_spatial_rgb_address_38aa69c - .incbin "@MGC_SPATIAL_RGB_CAPSULE@", 0x2b334, 0x5d0 - -.section .note.GNU-stack,"",@progbits diff --git a/app/src/main/java/com/hinnka/mycamera/processor/GlesMgcGreenDemosaicShaders.kt b/app/src/main/java/com/hinnka/mycamera/processor/GlesMgcGreenDemosaicShaders.kt new file mode 100644 index 00000000..bc03b9f5 --- /dev/null +++ b/app/src/main/java/com/hinnka/mycamera/processor/GlesMgcGreenDemosaicShaders.kt @@ -0,0 +1,345 @@ +package com.hinnka.mycamera.processor + +/** + * Green reconstruction shared by two MGC Halide AOTs that contain the same `g_gb` / `g_b` Funcs: + * + * - MGC 9.6.080 V24 `gcam::ResolveSabreHalide`, whose input is the quantized Sabre colour + * ([GlesMgcSabreResolveShaders]); + * - MGC 9.7.047 V25 `gcam::DemosaicGreenRaw16Halide` (libgcastartup.so wrapper 0x38AEE1C, + * worker 0x38AA69C), which MergeRgbRaw16F16 calls per burst frame through + * DemosaicGreenRawBurst. Its input is the RAW16 frame converted by [convertRaw16]. + * + * Both AOTs work in a virtual RGGB frame whose (0, 0) is the red site of the sensor CFA, so for a + * non-RGGB sensor the output is shifted by the red-site offset. Every pass writes an int16 plane + * padded by [PLANE_PADDING] on each side; the conversion pass resolves the AOT's boundary + * condition, so the green passes evaluate out-of-range sites from those padded samples exactly as + * the AOT does. The algorithm notes live in tools/mgc_sabre_resolve and tools/mgc_demosaic_green. + * + * The integer demosaic keeps the NEON lane semantics of the AOTs: 16-bit wraparound, SHADD/SRHADD + * rounding, SABD magnitudes, SQADD/SQSUB saturation and SSHL by a signed byte. + */ +internal object GlesMgcGreenDemosaicShaders { + const val PLANE_PADDING = 4 + + val header = """ + #version 310 es + precision highp float; + precision highp int; + precision highp sampler2D; + precision highp isampler2D; + precision highp usampler2D; + """.trimIndent() + + val integerOps = """ + const int PLANE_PADDING = $PLANE_PADDING; + + int s16(int v) { return (v << 16) >> 16; } + int u16(int v) { return v & 0xffff; } + int clz16(int x) { return x == 0 ? 16 : 15 - findMSB(x); } + int clz32(uint x) { return x == 0u ? 32 : 31 - findMSB(x); } + + // SSHL .8h: the shift is the signed low byte of the lane; negative shifts are arithmetic. + int sshl16(int x, int lane) { + int s = ((lane & 0xff) << 24) >> 24; + if (s >= 0) return s >= 16 ? 0 : s16(x << s); + if (s <= -16) return x < 0 ? -1 : 0; + return x >> (-s); + } + int shadd(int a, int b) { return (a + b) >> 1; } + int srhadd(int a, int b) { return (a + b + 1) >> 1; } + int sabd(int a, int b) { return abs(a - b); } + int urhadd(int a, int b) { return (a + b + 1) >> 1; } + int sqadd(int a, int b) { return clamp(a + b, -32768, 32767); } + int sqsub(int a, int b) { return clamp(a - b, -32768, 32767); } + + // Inverse-gradient pair blend. Candidate A has error dA, candidate B has error dB. + struct Ig1 { + bool aIsNear; + int shift; + }; + Ig1 makeIg1(int dA, int dB) { + int hA = dA >> 1; + int hB = dB >> 1; + int total = max(u16(hA + hB), 1); + return Ig1(hB > hA, clz16(total) - clz16(min(hA, hB))); + } + int blend1(Ig1 g, int xA, int xB) { + int nearValue = g.aIsNear ? xA : xB; + int farValue = g.aIsNear ? xB : xA; + return s16(nearValue + sshl16(s16(farValue - nearValue), g.shift)); + } + + // Inverse-squared-cost blend; X has cost cX and Y has cost cY. + int ig2(int cX, int cY, int x, int y) { + uint sX = (uint(cX) * uint(cX)) >> 1; + uint sY = (uint(cY) * uint(cY)) >> 1; + bool xIsNear = sY > sX; + int nearValue = xIsNear ? x : y; + int farValue = xIsNear ? y : x; + uint total = max(sX + sY, 1u); + int shift = clamp(s16(clz32(total) - clz32(min(sX, sY))), -15, 15); + return s16(nearValue + sshl16(s16(farValue - nearValue), shift)); + } + + // Bit below the leading one: the half-step fraction of log2(x). + int log2Fraction(int x) { return sshl16(x, clz16(u16(x)) - 14) & 1; } + + // Log-domain ratio correction: xWeighted * g / gWeighted in half-step powers of two. + int ratioCorrect(int xWeighted, int g, int gWeighted) { + int xp = max(xWeighted, 0); + int m = max(xp, max(gWeighted, g)); + int l = s16( + log2Fraction(xp) - 2 * clz16(u16(xp)) + 2 * clz16(u16(m)) - log2Fraction(m) + ); + int t = sshl16(sqsub(g, gWeighted), max(s16(l >> 1), -15)); + int odd = (l & 1) != 0 ? t >> 1 : 0; + return sqadd(xWeighted, s16(odd + t)); + } + + int planeAt(isampler2D plane, ivec2 planeSize, int u, int v) { + ivec2 p = clamp( + ivec2(u + PLANE_PADDING, v + PLANE_PADDING), + ivec2(0), + planeSize - ivec2(1) + ); + return texelFetch(plane, p, 0).r; + } + """.trimIndent() + + /** + * Chroma interpolation of the AOTs' integer demosaic: colour `wantBlue ? B : R` at a site of + * the virtual RGGB frame whose native colour differs. The including shader defines + * `int converted(int u, int v)` (R/B CFA samples) and `int green(int u, int v)`. + */ + val chromaOps = """ + // Chroma of colour `wantBlue ? B : R` at a site whose native colour differs. + int chroma(int u, int v, bool wantBlue) { + int nativeOffset = wantBlue ? 1 : 0; + bool sameRow = ((v - nativeOffset) & 1) == 0; + bool sameColumn = ((u - nativeOffset) & 1) == 0; + int gc = green(u, v); + if (sameRow && !sameColumn) { + Ig1 g = makeIg1(sabd(gc, green(u + 1, v)), sabd(gc, green(u - 1, v))); + int xWeighted = blend1(g, converted(u + 1, v), converted(u - 1, v)); + int gWeighted = blend1(g, green(u + 1, v), green(u - 1, v)); + return ratioCorrect(xWeighted, gc, gWeighted); + } + if (!sameRow && sameColumn) { + Ig1 g = makeIg1(sabd(gc, green(u, v + 1)), sabd(gc, green(u, v - 1))); + int xWeighted = blend1(g, converted(u, v + 1), converted(u, v - 1)); + int gWeighted = blend1(g, green(u, v + 1), green(u, v - 1)); + return ratioCorrect(xWeighted, gc, gWeighted); + } + int center = converted(u, v); + int topLeft = converted(u - 1, v - 1); + int topRight = converted(u + 1, v - 1); + int bottomLeft = converted(u - 1, v + 1); + int bottomRight = converted(u + 1, v + 1); + Ig1 g1 = makeIg1(sabd(gc, green(u + 1, v - 1)), sabd(gc, green(u - 1, v + 1))); + int x1 = ratioCorrect( + blend1(g1, topRight, bottomLeft), + gc, + blend1(g1, green(u + 1, v - 1), green(u - 1, v + 1)) + ); + Ig1 g2 = makeIg1(sabd(gc, green(u + 1, v + 1)), sabd(gc, green(u - 1, v - 1))); + int x2 = ratioCorrect( + blend1(g2, bottomRight, topLeft), + gc, + blend1(g2, green(u + 1, v + 1), green(u - 1, v - 1)) + ); + int cost2 = urhadd(sabd(center, topLeft), sabd(center, bottomRight)); + int cost1 = urhadd(sabd(center, bottomLeft), sabd(center, topRight)); + return ig2(cost2, cost1, x2, x1); + } + """.trimIndent() + + /** + * RAW16 access shared by DemosaicGreenRaw16 and MergeRgbRaw16F16: the sensor code at a site of + * the virtual RGGB frame under `mirror_image`, which mirrors the sensor's four colour planes + * (plane index -1 reads 0), so a virtual site outside the RAW keeps its colour, and its + * `wb_gains_applied` int16 conversion. The including shader declares uRaw, uRawSize, uRedSite, + * uBlackLevels and uConversionGains. + */ + val raw16Ops = """ + // Halide mirror_image: period 2 * extent, index -1 reads 0 and extent reads extent - 1. + int mirrorIndex(int index, int extent) { + int period = 2 * extent; + // GLSL ES leaves % undefined for negative operands, so fold a non-negative index of + // the same residue. + int lifted = index < 0 ? index + period * ((period - 1 - index) / period) : index; + int folded = lifted % period; + return folded < extent ? folded : period - 1 - folded; + } + + int mirrorSite(int site, int extent) { + return 2 * mirrorIndex(site >> 1, extent >> 1) + (site & 1); + } + + float sensorValue(ivec2 virtualSite) { + ivec2 sensorSite = virtualSite + uRedSite; + ivec2 source = ivec2( + mirrorSite(sensorSite.x, uRawSize.x), + mirrorSite(sensorSite.y, uRawSize.y) + ); + uint code = texelFetch(uRaw, source, 0).r; + // 2^23 + code is exact in binary32, so the subtraction yields float(code) exactly + // without an integer-to-float conversion a driver could lower to FP16. + return uintBitsToFloat(0x4B000000u | code) - 8388608.0; + } + + // R, Gr, Gb, B index of a virtual site. + int cfaChannel(ivec2 virtualSite) { + return (virtualSite.x & 1) + 2 * (virtualSite.y & 1); + } + + int saturateInt16(float value) { + return int(clamp(roundEven(value), -32768.0, 32767.0)); + } + + // `wb_gains_applied`; the including shader declares uBlackLevels and uConversionGains. + int convertedSample(ivec2 virtualSite) { + int channel = cfaChannel(virtualSite); + return saturateInt16( + (sensorValue(virtualSite) - uBlackLevels[channel]) * uConversionGains[channel] + ); + } + """.trimIndent() + + /** + * DemosaicGreenRaw16 pass 1, `wb_gains_applied` over the padded plane: + * int16(clamp(roundEven((raw - black[c]) * wb[c] * overallGain), -32768, 32767)). + */ + val convertRaw16 = """ + ${header.prependIndent(" ").trimStart()} + uniform highp usampler2D uRaw; + uniform ivec2 uRawSize; + uniform ivec2 uRedSite; + uniform vec4 uBlackLevels; + // whiteBalanceGains[c] * overallGain. + uniform vec4 uConversionGains; + layout(location = 0) out highp ivec4 oConverted; + + ${raw16Ops.prependIndent(" ").trimStart()} + + void main() { + ivec2 virtualSite = ivec2(gl_FragCoord.xy) - ivec2($PLANE_PADDING); + oConverted = ivec4(convertedSample(virtualSite), 0, 0, 0); + } + """.trimIndent() + + /** + * Pass 2, `g_gb`: blur = (4G + diagonal G + 4) >> 3 and + * G' = blur + (((G - blur) * k + 0x8000) >> 16), where k = 0 equalizes Gr/Gb fully. + */ + val greenBalance = """ + ${header.prependIndent(" ").trimStart()} + uniform highp isampler2D uConverted; + uniform ivec2 uPlaneSize; + uniform int uGreenImbalanceRetention; + layout(location = 0) out highp ivec4 oBalanced; + + ${integerOps.prependIndent(" ").trimStart()} + + int converted(int u, int v) { return planeAt(uConverted, uPlaneSize, u, v); } + + void main() { + ivec2 virtualSite = ivec2(gl_FragCoord.xy) - ivec2(PLANE_PADDING); + int u = virtualSite.x; + int v = virtualSite.y; + int g = converted(u, v); + if (((u + v) & 1) == 0) { + oBalanced = ivec4(g, 0, 0, 0); + return; + } + int total = 4 * g + converted(u - 1, v - 1) + converted(u + 1, v - 1) + + converted(u - 1, v + 1) + converted(u + 1, v + 1); + int blur = s16((total + 4) >> 3); + int difference = s16(g - blur); + int correction = s16( + int(uint(difference * uGreenImbalanceRetention) + 0x8000u) >> 16 + ); + oBalanced = ivec4(s16(correction + blur), 0, 0, 0); + } + """.trimIndent() + + /** + * Pass 3, `g_b$1`: green at R/B sites from directional (G + C) / 2 estimates, inverse-gradient + * candidate blends, log-domain ratio correction and inverse-squared direction costs. + */ + val greenAtColor = """ + ${header.prependIndent(" ").trimStart()} + uniform highp isampler2D uBalanced; + uniform ivec2 uPlaneSize; + layout(location = 0) out highp ivec4 oGreen; + + ${integerOps.prependIndent(" ").trimStart()} + + // R/B sites hold the converted value, G sites the balanced green. + int at(int u, int v) { return planeAt(uBalanced, uPlaneSize, u, v); } + + void main() { + ivec2 virtualSite = ivec2(gl_FragCoord.xy) - ivec2(PLANE_PADDING); + int u = virtualSite.x; + int v = virtualSite.y; + int c = at(u, v); + if (((u + v) & 1) != 0) { + oGreen = ivec4(c, 0, 0, 0); + return; + } + int cL = at(u - 2, v); + int cR = at(u + 2, v); + int cU = at(u, v - 2); + int cD = at(u, v + 2); + int gl = at(u - 1, v); + int gr = at(u + 1, v); + int gu = at(u, v - 1); + int gd = at(u, v + 1); + int ul = at(u - 1, v - 1); + int ur = at(u + 1, v - 1); + int dl = at(u - 1, v + 1); + int dr = at(u + 1, v + 1); + + int eH = srhadd(shadd(gl, gr), c); + int eR = srhadd(shadd(c, cR), gr); + int eL = srhadd(shadd(cL, c), gl); + int eV = srhadd(shadd(gu, gd), c); + int eD = srhadd(shadd(c, cD), gd); + int eU = srhadd(shadd(cU, c), gu); + + Ig1 horizontal = makeIg1(sabd(eH, eR), sabd(eH, eL)); + int eHWeighted = blend1(horizontal, eR, eL); + int gH = blend1(horizontal, gr, gl); + Ig1 vertical = makeIg1(sabd(eV, eD), sabd(eV, eU)); + int eVWeighted = blend1(vertical, eD, eU); + int gV = blend1(vertical, gd, gu); + + int cH = shadd(srhadd(gl, gr), c); + int cV = shadd(srhadd(gu, gd), c); + int eHUpDown = srhadd( + shadd(srhadd(at(u - 1, v - 2), at(u + 1, v - 2)), cU), + shadd(srhadd(at(u - 1, v + 2), at(u + 1, v + 2)), cD) + ); + int eVLeftRight = srhadd( + shadd(srhadd(at(u - 2, v - 1), at(u - 2, v + 1)), cL), + shadd(srhadd(at(u + 2, v - 1), at(u + 2, v + 1)), cR) + ); + int pl = shadd(srhadd(ul, dl), gl); + int pr = shadd(srhadd(ur, dr), gr); + int pu = shadd(srhadd(ul, ur), gu); + int pd = shadd(srhadd(dl, dr), gd); + // (|.| >> 2) * 9 is a wrapping 16-bit MUL then USHR #3; the sums are USRA mod 2^16. + int costA = u16( + (u16((sabd(cV, eVLeftRight) >> 2) * 9) >> 3) + + (sabd(cV, srhadd(pl, pr)) >> 3) + (sabd(pl, pr) >> 1) + ); + int costB = u16( + (u16((sabd(cH, eHUpDown) >> 2) * 9) >> 3) + + (sabd(cH, srhadd(pu, pd)) >> 3) + (sabd(pu, pd) >> 1) + ); + + int greenH = ratioCorrect(gH, eH, eHWeighted); + int greenV = ratioCorrect(gV, eV, eVWeighted); + oGreen = ivec4(ig2(costB, costA, greenV, greenH), 0, 0, 0); + } + """.trimIndent() +} diff --git a/app/src/main/java/com/hinnka/mycamera/processor/GlesMgcRawSpatialShaders.kt b/app/src/main/java/com/hinnka/mycamera/processor/GlesMgcRawSpatialShaders.kt index 3e4c056e..ef4a69d0 100644 --- a/app/src/main/java/com/hinnka/mycamera/processor/GlesMgcRawSpatialShaders.kt +++ b/app/src/main/java/com/hinnka/mycamera/processor/GlesMgcRawSpatialShaders.kt @@ -1493,63 +1493,6 @@ internal object GlesMgcRawSpatialShaders { } """.trimIndent() - /** Converts native planar Q14 camera RGB to RGB16, without resampling before FinishRaw. */ - val normalizeAotRgb16 = """ - #version 300 es - precision highp float; - precision highp int; - precision highp sampler2D; - uniform sampler2D uChannelPlane; - uniform sampler2D uLensShading; - uniform sampler2D uUltrashortWeight; - uniform vec3 uCameraWhite; - uniform int uHasUltrashort; - uniform ivec2 uOutputSize; - uniform float uOutputExposureScale; - uniform int uUseLensShading; - uniform int uChannel; - layout(location = 0) out highp uvec4 oRgb16; - - void main() { - ivec2 p = ivec2(gl_FragCoord.xy); - vec2 uv = (vec2(p) + vec2(0.5)) / vec2(uOutputSize); - float value = texelFetch(uChannelPlane, p, 0).r * (1.0 / 16384.0); - float channelShading = 1.0; - if (uUseLensShading != 0) { - vec4 shading = texture(uLensShading, clamp(uv, vec2(0.0), vec2(1.0))); - channelShading = uChannel == 0 ? shading.r : - (uChannel == 1 ? 0.5 * (shading.g + shading.b) : shading.a); - } - // Sensor saturation precedes lens-shading correction, so CameraWhite bounds the - // unshaded sensor-domain value and the shading gain applies to the clipped result. - // Clipping after shading would cap unsaturated off-axis samples at the reference - // white, outside the (unshaded) highlight mask the ultrashort replaces. - // CameraWhite must follow the exposures that actually supply this pixel. - // A rejected short leaves the reference's saturated RGB at 1/ratio in the - // exported short domain; clipping it later against short-domain CameraWhite - // misses the reference plateau and preserves its false magenta chroma. - // The selected short slice has weight m and unit frame weight, while the - // reference slice alone keeps (1 - m); the short's share of the merge is thus - // at most m, and the merged white is bounded by mix(referenceWhite, shortWhite, m). - // The bound must stay continuous in m: switching on m > 0 steps the cap along - // the RAW/4 weight texel grid and draws a staircase through the highlight. - float shortShare = uHasUltrashort != 0 - ? clamp(texture(uUltrashortWeight, uv).r, 0.0, 1.0) - : 0.0; - float whiteScale = mix(uOutputExposureScale, 1.0, shortShare); - float cameraWhite = uCameraWhite[uChannel] * whiteScale; - float outputValue = - min(value * uOutputExposureScale, cameraWhite) * channelShading; - uint encodedValue = uint(round( - clamp(outputValue, 0.0, 1.0) * 65535.0 - )); - // CPU-side glColorMask selects the destination RGB component for this pass. - // Avoid dynamically indexing a fragment output, which is rejected by strict ES - // compilers even though dynamically indexing an ordinary local vector is legal. - oRgb16 = uvec4(uvec3(encodedValue), 0u); - } - """.trimIndent() - /** * First integer-to-float conversion stays in compute image load/store. Some Mali drivers * incorrectly lower the equivalent fragment-sampler uint16 conversion to FP16. diff --git a/app/src/main/java/com/hinnka/mycamera/processor/GlesMgcRawSpatialStacker.kt b/app/src/main/java/com/hinnka/mycamera/processor/GlesMgcRawSpatialStacker.kt index 130fc86f..05cc5bda 100644 --- a/app/src/main/java/com/hinnka/mycamera/processor/GlesMgcRawSpatialStacker.kt +++ b/app/src/main/java/com/hinnka/mycamera/processor/GlesMgcRawSpatialStacker.kt @@ -163,55 +163,12 @@ internal class GlesMgcRawSpatialStacker( val useFrameWeight: Boolean, ) - private data class RgbTileFrameRegion( - val frame: RgbMergeFrame, - val sourceRegion: MgcSpatialRgbRect, - val uploadRegion: MgcSpatialRgbRect, - ) - - private data class RgbBandPlan( - val bands: List, - val work: List>>, - val maximumOutputWidth: Int, - val maximumOutputHeight: Int, - val maximumDiagnosticWidth: Int, - val maximumDiagnosticHeight: Int, - val maximumSourceWidth: Int, - val maximumSourceHeight: Int, - val maximumUploadWidth: Int, - val maximumUploadHeight: Int, - val projectedGpuBytes: Long, - ) - private data class RgbMergeOutput( val cpuBuffer: ByteBuffer?, val gpuTexture: Int, - val diagnosticFixed16: PreparedTextureReadback?, val completionTimeline: GpuStackCompletionTimeline?, ) - /** - * Full-output RGB accumulation used by the performance path. - * - * RAW stays frame-sequential: the current image is uploaded once, its temporal products are - * consumed immediately, and only the two full-resolution additive accumulators survive until - * normalization. Draw bands bound individual GPU jobs; they never trigger another RAW upload. - */ - private data class OnlineRgbAccumulator( - val semanticAccumulator: Int, - val opponentWeightAccumulator: Int, - val chromaGuideTexture: Int, - val drawBands: List, - val rawSlots: IntArray, - val passWindow: GlesGpuScheduler.PassWindow, - val projectedGpuBytes: Long, - var nextRawSlot: Int, - var contributedFrames: Int = 0, - var rawUploadCount: Int = 0, - var rawUploadBytes: Long = 0L, - var rawUploadNs: Long = 0L, - ) - private data class TextureSpec( val width: Int, val height: Int, @@ -318,59 +275,6 @@ internal class GlesMgcRawSpatialStacker( val rejectionHeight: Int get() = geometry.rejectionHeight } - private data class PixelPackBuffer( - val buffer: Int, - val byteCount: Int, - ) - - private data class QueuedTextureReadback( - val storage: PixelPackBuffer, - val mode: String, - val targetBindMs: Long, - val readSubmitMs: Long, - val totalSubmitMs: Long, - ) - - private data class PreparedTextureReadback( - val byteCount: Int, - val queuedGpuReadback: QueuedTextureReadback?, - val cpuBuffer: ByteBuffer?, - val mode: String, - val targetBindMs: Long, - val readSubmitMs: Long, - val totalSubmitMs: Long, - ) { - init { - require(byteCount > 0) - require((queuedGpuReadback == null) != (cpuBuffer == null)) { - "Fixed16 readback must own exactly one GPU or CPU storage" - } - require(queuedGpuReadback?.storage?.byteCount == null || - queuedGpuReadback.storage.byteCount == byteCount) - require(cpuBuffer?.capacity() == null || cpuBuffer.capacity() >= byteCount) - } - } - - private data class RgbDiagnosticPackTiming( - val setupNs: Long, - val dispatchNs: Long, - val byteCount: Int, - val destinationHeight: Int, - ) - - private data class PendingRgbDiagnosticBand( - val storage: PixelPackBuffer, - val outputCore: MgcSpatialRgbRect, - val destinationHeight: Int, - val byteCount: Int, - ) - - private enum class StrengthReadbackEncoding { - FLOAT32, - UNORM8, - SINT16, - } - private data class BayerKernelTuning( val referenceSignal: Float, val referenceGreenShotNoiseFactor: Float, @@ -411,10 +315,8 @@ internal class GlesMgcRawSpatialStacker( private val outputWidth = width private val outputHeight = height // MergeRgbRaw16F16 is a native-grid merge: output coordinates are RAW coordinates and samples - // outside the RAW extent use its mirror boundary. Only its private planar allocation is padded - // to complete 16x16 tiles. Display scaling belongs after FinishRaw/GuidedUpsample. - private val rgbAotStorageWidth = ceilDiv(width, RGB_AOT_TILE_SIZE) * RGB_AOT_TILE_SIZE - private val rgbAotStorageHeight = ceilDiv(height, RGB_AOT_TILE_SIZE) * RGB_AOT_TILE_SIZE + // outside the RAW extent use its mirror boundary. Display scaling belongs after + // FinishRaw/GuidedUpsample. private val sensorWhiteLevelCode = max(1, whiteLevel) private val sensorWhiteLevel = sensorWhiteLevelCode.toFloat() // RawMetadata has already converted positional Camera2 black levels to R, Gr, Gb, B. @@ -477,7 +379,6 @@ internal class GlesMgcRawSpatialStacker( private var guideProgram = 0 private var covarianceProgram = 0 - private var rgbChromaGuideProgram = 0 private var rawToGrayProgram = 0 private var downsampleProgram = 0 private var downsample4Program = 0 @@ -525,16 +426,15 @@ internal class GlesMgcRawSpatialStacker( /** §2.2 merge variance accumulator of the merge in flight; released with the merge. */ private var mergeNoise: PhotonMergeNoise? = null private var currentMergeCovariance = 0 - private var mergeRgbProgram = 0 private var normalizeBayerProgram = 0 - private var normalizeRgbProgram = 0 - private var normalizeAotRgbProgram = 0 + // MergeRgbRaw16F16 on the GPU: per-frame DemosaicGreenRaw16, accumulation and resolve. + private var spatialRgbConvertProgram = 0 + private var spatialRgbGreenBalanceProgram = 0 + private var spatialRgbGreenProgram = 0 + private var spatialRgbAccumulateProgram = 0 + private var spatialRgbResolveProgram = 0 private var copyRgb16ToFloatProgram = 0 private var rgbChromaPostprocessor: GlesMgcSpatialRgbChromaPostprocessor? = null - private var packRgbFixed16FallbackProgram = 0 - private var strengthFloatPackProgram = 0 - private var strengthUnorm8PackProgram = 0 - private var strengthSint16PackProgram = 0 private var supportsComputePrograms = false private var supportsComputeReadback = false private var maxShaderStorageBlockBytes = 0L @@ -615,8 +515,6 @@ internal class GlesMgcRawSpatialStacker( var exportedBayerTexture = 0 var exportedRgbTexture = 0 var exportedRgbCompletionTimeline: GpuStackCompletionTimeline? = null - var strengthAlignmentHostBuffer: ByteBuffer? = null - var strengthRejectionHostBuffer: ByteBuffer? = null var strengthCapture: StrengthCapture? = null var fastMomentsRawStats: RawSceneAERawStats? = null val processStartNs = System.nanoTime() @@ -1861,8 +1759,8 @@ internal class GlesMgcRawSpatialStacker( "MGC Spatial RGB admitted ${rgbMergeFrames.size} frames, " + "but Bayer/noise merge admitted $mergedFrames" } - val aotCapture = checkNotNull(readyStrengthCapture) { - "MGC Spatial RGB AOT inputs were not captured" + val mergeCapture = checkNotNull(readyStrengthCapture) { + "MGC Spatial RGB merge inputs were not captured" } val temporalGpuBytes = estimatedOwnedTextureBytes() PLog.i( @@ -1881,22 +1779,16 @@ internal class GlesMgcRawSpatialStacker( // RGB normalization still needs the selected short's actual RAW/4 // acceptance to distinguish reference fallback from recovered HDR. persistentTextures = intArrayOf(rgbUltrashortWeight), - strengthCapture = aotCapture, + strengthCapture = mergeCapture, ) - val preparedStrengthAtlases = materializeRgbStrengthAtlases(aotCapture).also { - strengthAlignmentHostBuffer = it.first.cpuBuffer - strengthRejectionHostBuffer = it.second.cpuBuffer - } val rgbMergeStartNs = System.nanoTime() - val rgbOutput = renderOriginalAotRgbMerge( + val rgbOutput = renderSpatialRgbMerge( frames = rgbMergeFrames, images = images, outputExposureScale = outputExposure.normalizationScale, ultrashortWeight = rgbUltrashortWeight, mergeSharpness = finishRawSharpenAttenuationScale, - capture = aotCapture, - preparedAlignment = preparedStrengthAtlases.first, - preparedRejection = preparedStrengthAtlases.second, + capture = mergeCapture, ) cpuOutput = rgbOutput.cpuBuffer exportedRgbTexture = rgbOutput.gpuTexture @@ -1906,9 +1798,8 @@ internal class GlesMgcRawSpatialStacker( TAG, "MGC Spatial RGB dispatch complete frames=$mergedFrames " + "took=${(System.nanoTime() - rgbMergeStartNs) / 1_000_000L}ms " + - "mode=mgc-v25-merge-rgb-raw16-f16-aot " + - "aotNative=${width}x$height " + - "aotStorage=${rgbAotStorageWidth}x$rgbAotStorageHeight", + "mode=mgc-v25-merge-rgb-raw16-f16-gles " + + "native=${width}x$height", ) } else { val bayer16 = renderBayer16( @@ -1941,7 +1832,7 @@ internal class GlesMgcRawSpatialStacker( "lscApplied=$lensShadingCorrectionApplied result=$resultLabel " + "programInit=${programInitMs}ms " + "queueMode=${if (outputMode == MgcSpatialOutputMode.RGB) { - "mgc-v25-native-aot" + "mgc-v25-gles" } else { "ordered-continuous" }} " + @@ -2001,8 +1892,6 @@ internal class GlesMgcRawSpatialStacker( images.forEach { it.close() } release() GlesGpuScheduler.restoreCurrentThreadPriority(originalThreadPriority, TAG) - LargeDirectBuffer.free(strengthAlignmentHostBuffer) - LargeDirectBuffer.free(strengthRejectionHostBuffer) if (!returned) { exportedRgbCompletionTimeline?.releasePending() LargeDirectBuffer.free(cpuOutput) @@ -2825,7 +2714,7 @@ internal class GlesMgcRawSpatialStacker( 3 -> 1 to 1 // BGGR else -> throw IllegalArgumentException("MGC Sabre Resolve CFA pattern $cfaPattern") } - val padding = GlesMgcSabreResolveShaders.PLANE_PADDING + val padding = GlesMgcGreenDemosaicShaders.PLANE_PADDING val planeWidth = width + 2 * padding val planeHeight = height + 2 * padding val converted = createTexture(planeWidth, planeHeight, GLES30.GL_R16I, GLES30.GL_NEAREST) @@ -2943,11 +2832,11 @@ internal class GlesMgcRawSpatialStacker( "mgc_sabre_resolve_convert_to_int", ) sabreResolveGreenBalanceProgram = linkProgram( - GlesMgcSabreResolveShaders.greenBalance, + GlesMgcGreenDemosaicShaders.greenBalance, "mgc_sabre_resolve_green_balance", ) sabreResolveGreenProgram = linkProgram( - GlesMgcSabreResolveShaders.greenAtColor, + GlesMgcGreenDemosaicShaders.greenAtColor, "mgc_sabre_resolve_green_at_color", ) sabreResolveOutputProgram = linkProgram( @@ -3130,11 +3019,27 @@ internal class GlesMgcRawSpatialStacker( check(supportsComputePrograms) { "MGC Spatial RGB color noise/IIR requires the GLES 3.1 compute baseline" } + spatialRgbConvertProgram = linkProgram( + GlesMgcGreenDemosaicShaders.convertRaw16, + "mgc_spatial_v25_green_convert_raw16", + ) + spatialRgbGreenBalanceProgram = linkProgram( + GlesMgcGreenDemosaicShaders.greenBalance, + "mgc_spatial_v25_green_balance", + ) + spatialRgbGreenProgram = linkProgram( + GlesMgcGreenDemosaicShaders.greenAtColor, + "mgc_spatial_v25_green_at_color", + ) + spatialRgbAccumulateProgram = linkComputeProgram( + GlesMgcSpatialRgbMergeShaders.accumulateFrame, + "mgc_spatial_v25_rgb_accumulate", + ) // Color noise/IIR owns a fixed RGBA16UI boundary, matching the VGN/Radiance - // contract. The original planar F16 AOT output enters that boundary exactly once. - normalizeAotRgbProgram = linkProgram( - GlesMgcRawSpatialShaders.normalizeAotRgb16, - "mgc_spatial_v25_aot_rgb16ui", + // contract. The merged F16 output enters that boundary exactly once. + spatialRgbResolveProgram = linkProgram( + GlesMgcSpatialRgbMergeShaders.resolve, + "mgc_spatial_v25_rgb_resolve", ) if (exportGpuLinearRgbSource && gpuLinearRgbStorage == GpuLinearRgbStorage.RGBA16F @@ -3152,27 +3057,6 @@ internal class GlesMgcRawSpatialStacker( GlesMgcRawSpatialShaders.normalizeBayer, "mgc_spatial_bayer16", ) - if (supportsComputeReadback) { - runCatching { - strengthFloatPackProgram = linkComputeProgram( - MgcStrengthReadbackShaders.FLOAT32, - "mgc_strength_pack_float32", - ) - strengthUnorm8PackProgram = linkComputeProgram( - MgcStrengthReadbackShaders.UNORM8, - "mgc_strength_pack_unorm8", - ) - strengthSint16PackProgram = linkComputeProgram( - MgcStrengthReadbackShaders.SINT16, - "mgc_strength_pack_sint16", - ) - }.onFailure { error -> - strengthFloatPackProgram = 0 - strengthUnorm8PackProgram = 0 - strengthSint16PackProgram = 0 - PLog.w(TAG, "MGC strength SSBO pack unavailable; using framebuffer readback", error) - } - } } private fun createRgbChromaPostprocessor( @@ -5555,400 +5439,6 @@ internal class GlesMgcRawSpatialStacker( ) } - private fun strengthAlignmentReadbackByteCount(capture: StrengthCapture): Int = - ( - capture.alignmentWidth.toLong() * capture.alignmentHeight * - capture.frameCount * 2L * Float.SIZE_BYTES - ).also { bytes -> require(bytes in 1..Int.MAX_VALUE.toLong()) } - .toInt() - - private fun strengthRejectionReadbackByteCount(capture: StrengthCapture): Int = - ( - capture.rejectionWidth.toLong() * capture.rejectionHeight * capture.frameCount - ).also { bytes -> require(bytes in 1..Int.MAX_VALUE.toLong()) } - .toInt() - - private fun strengthFixed16ReadbackByteCount(capture: StrengthCapture): Int = - (capture.geometry.fixed16SampleCount * Short.SIZE_BYTES) - .also { bytes -> require(bytes in 1..Int.MAX_VALUE.toLong()) } - .toInt() - - private fun allocatePixelPackBuffer( - byteCount: Int, - label: String, - ): PixelPackBuffer { - require(byteCount > 0) - val ids = IntArray(1) - GLES30.glGenBuffers(1, ids, 0) - val buffer = ids[0] - check(buffer != 0) { "$label glGenBuffers returned 0" } - buffers += buffer - GLES30.glBindBuffer(GLES30.GL_PIXEL_PACK_BUFFER, buffer) - val allocationByteCount = ((byteCount.toLong() + 3L) and -4L) - .also { bytes -> require(bytes <= Int.MAX_VALUE) } - .toInt() - GLES30.glBufferData( - GLES30.GL_PIXEL_PACK_BUFFER, - allocationByteCount, - null, - GLES30.GL_STREAM_READ, - ) - GLES30.glBindBuffer(GLES30.GL_PIXEL_PACK_BUFFER, 0) - checkGlError("allocate $label PBO") - return PixelPackBuffer(buffer, byteCount) - } - - private fun releasePixelPackBuffer(storage: PixelPackBuffer, label: String) { - if (!buffers.remove(storage.buffer)) return - GLES30.glDeleteBuffers(1, intArrayOf(storage.buffer), 0) - checkGlError("release $label") - } - - private fun queueTextureReadback( - texture: Int, - textureWidth: Int, - textureHeight: Int, - encoding: StrengthReadbackEncoding, - storage: PixelPackBuffer, - label: String, - atlasLayout: MgcSpatialStrengthAtlasLayout? = null, - ): QueuedTextureReadback { - atlasLayout?.let { layout -> - require(layout.atlasWidth == textureWidth && layout.atlasHeight == textureHeight) - } - val bytesPerValue = when (encoding) { - StrengthReadbackEncoding.FLOAT32 -> Float.SIZE_BYTES - StrengthReadbackEncoding.UNORM8 -> Byte.SIZE_BYTES - StrengthReadbackEncoding.SINT16 -> Short.SIZE_BYTES - } - val logicalValueCount = atlasLayout?.logicalValueCount - ?: textureWidth.toLong() * textureHeight - require(logicalValueCount * bytesPerValue == storage.byteCount.toLong()) { - "$label logical readback size does not match storage: " + - "values=$logicalValueCount bytesPerValue=$bytesPerValue " + - "storage=${storage.byteCount}" - } - val packProgram = when (encoding) { - StrengthReadbackEncoding.FLOAT32 -> strengthFloatPackProgram - StrengthReadbackEncoding.UNORM8 -> strengthUnorm8PackProgram - StrengthReadbackEncoding.SINT16 -> strengthSint16PackProgram - } - val invocationCount = when (encoding) { - StrengthReadbackEncoding.FLOAT32 -> logicalValueCount - StrengthReadbackEncoding.UNORM8 -> (logicalValueCount + 3L) / 4L - StrengthReadbackEncoding.SINT16 -> (logicalValueCount + 1L) / 2L - } - val requiredGroupCount = - (invocationCount + GlesComputeWorkGroup.LINEAR_SIZE - 1L) / - GlesComputeWorkGroup.LINEAR_SIZE - val packedStorageBytes = (storage.byteCount.toLong() + 3L) and -4L - val hasComputeDispatchCapacity = - requiredGroupCount <= maxComputePackGroupsX.toLong() * maxComputePackGroupsY - if (packProgram != 0 && - packedStorageBytes <= maxShaderStorageBlockBytes && - hasComputeDispatchCapacity - ) { - val dispatch = createMgcSpatialStrengthPackDispatch( - invocationCount = invocationCount, - localSize = GlesComputeWorkGroup.LINEAR_SIZE, - maximumGroupsX = maxComputePackGroupsX, - maximumGroupsY = maxComputePackGroupsY, - ) - return queueTextureSsboPack( - texture = texture, - textureWidth = textureWidth, - textureHeight = textureHeight, - encoding = encoding, - storage = storage, - program = packProgram, - label = label, - atlasLayout = atlasLayout, - invocationCount = invocationCount, - dispatch = dispatch, - ) - } - if (packProgram != 0 && packedStorageBytes > maxShaderStorageBlockBytes) { - PLog.w( - TAG, - "MGC Spatial strength SSBO pack exceeds device block limit; " + - "label=$label bytes=$packedStorageBytes " + - "max=$maxShaderStorageBlockBytes, using framebuffer readback", - ) - } - if (packProgram != 0 && !hasComputeDispatchCapacity) { - PLog.w( - TAG, - "MGC Spatial strength SSBO pack exceeds device dispatch grid; " + - "label=$label groups=$requiredGroupCount " + - "max=${maxComputePackGroupsX}x$maxComputePackGroupsY, " + - "using framebuffer readback", - ) - } - val totalStartNs = System.nanoTime() - val targetBindStartNs = System.nanoTime() - bindRenderTargets(intArrayOf(texture), label) - val targetBindMs = (System.nanoTime() - targetBindStartNs) / 1_000_000L - GLES30.glBindBuffer(GLES30.GL_PIXEL_PACK_BUFFER, storage.buffer) - GLES30.glPixelStorei(GLES30.GL_PACK_ALIGNMENT, 1) - GLES30.glPixelStorei(GLES30.GL_PACK_ROW_LENGTH, 0) - val readSubmitStartNs = System.nanoTime() - val readFormat = when (encoding) { - StrengthReadbackEncoding.FLOAT32, - StrengthReadbackEncoding.UNORM8 -> GLES30.GL_RED - StrengthReadbackEncoding.SINT16 -> GLES30.GL_RED_INTEGER - } - val readType = when (encoding) { - StrengthReadbackEncoding.FLOAT32 -> GLES30.GL_FLOAT - StrengthReadbackEncoding.UNORM8 -> GLES30.GL_UNSIGNED_BYTE - StrengthReadbackEncoding.SINT16 -> GLES30.GL_SHORT - } - if (atlasLayout == null || atlasLayout.columns == 1) { - GLES30.glReadPixels( - 0, - 0, - textureWidth, - textureHeight, - readFormat, - readType, - 0, - ) - } else { - for (plane in 0 until atlasLayout.planeCount) { - val byteOffset = (atlasLayout.planeValueCount * plane * bytesPerValue) - .also { offset -> require(offset <= Int.MAX_VALUE) } - .toInt() - GLES30.glReadPixels( - atlasLayout.originX(plane), - atlasLayout.originY(plane), - atlasLayout.planeWidth, - atlasLayout.planeHeight, - readFormat, - readType, - byteOffset, - ) - } - } - val readSubmitMs = (System.nanoTime() - readSubmitStartNs) / 1_000_000L - GLES30.glBindBuffer(GLES30.GL_PIXEL_PACK_BUFFER, 0) - GLES30.glBindFramebuffer(GLES30.GL_FRAMEBUFFER, 0) - checkGlError("queue $label") - return QueuedTextureReadback( - storage = storage, - mode = if (atlasLayout == null || atlasLayout.columns == 1) { - "framebuffer-readpixels" - } else { - "framebuffer-readpixels-atlas" - }, - targetBindMs = targetBindMs, - readSubmitMs = readSubmitMs, - totalSubmitMs = (System.nanoTime() - totalStartNs) / 1_000_000L, - ).also { queued -> - PLog.i( - TAG, - "MGC Spatial strength PBO submit label=$label " + - "mode=${queued.mode} bytes=${storage.byteCount} " + - "setup=${queued.targetBindMs}ms submit=${queued.readSubmitMs}ms " + - "total=${queued.totalSubmitMs}ms", - ) - } - } - - private fun queuePreparedTextureReadback( - texture: Int, - textureWidth: Int, - textureHeight: Int, - encoding: StrengthReadbackEncoding, - byteCount: Int, - label: String, - atlasLayout: MgcSpatialStrengthAtlasLayout? = null, - ): PreparedTextureReadback { - val storage = allocatePixelPackBuffer(byteCount, label) - val queued = queueTextureReadback( - texture = texture, - textureWidth = textureWidth, - textureHeight = textureHeight, - encoding = encoding, - storage = storage, - label = label, - atlasLayout = atlasLayout, - ) - return PreparedTextureReadback( - byteCount = queued.storage.byteCount, - queuedGpuReadback = queued, - cpuBuffer = null, - mode = queued.mode, - targetBindMs = queued.targetBindMs, - readSubmitMs = queued.readSubmitMs, - totalSubmitMs = queued.totalSubmitMs, - ) - } - - private fun queueTextureSsboPack( - texture: Int, - textureWidth: Int, - textureHeight: Int, - encoding: StrengthReadbackEncoding, - storage: PixelPackBuffer, - program: Int, - label: String, - atlasLayout: MgcSpatialStrengthAtlasLayout?, - invocationCount: Long, - dispatch: MgcSpatialStrengthPackDispatch, - ): QueuedTextureReadback { - val totalStartNs = System.nanoTime() - val setupStartNs = System.nanoTime() - GLES31.glUseProgram(program) - GLES31.glActiveTexture(GLES31.GL_TEXTURE0) - GLES31.glBindTexture(GLES31.GL_TEXTURE_2D, texture) - GLES31.glUniform1i(GLES31.glGetUniformLocation(program, "uSource"), 0) - val planeWidth = atlasLayout?.planeWidth ?: textureWidth - val planeHeight = atlasLayout?.planeHeight ?: textureHeight - val planeCount = atlasLayout?.planeCount ?: 1 - val atlasColumns = atlasLayout?.columns ?: 1 - GLES31.glUniform2i( - GLES31.glGetUniformLocation(program, "uPlaneSize"), - planeWidth, - planeHeight, - ) - GLES31.glUniform1i( - GLES31.glGetUniformLocation(program, "uPlaneCount"), - planeCount, - ) - GLES31.glUniform1i( - GLES31.glGetUniformLocation(program, "uAtlasColumns"), - atlasColumns, - ) - GLES31.glBindBufferBase(GLES31.GL_SHADER_STORAGE_BUFFER, 0, storage.buffer) - val setupMs = (System.nanoTime() - setupStartNs) / 1_000_000L - val valueCount = planeWidth.toLong() * planeHeight * planeCount - val expectedInvocationCount = when (encoding) { - StrengthReadbackEncoding.FLOAT32 -> valueCount - StrengthReadbackEncoding.UNORM8 -> (valueCount + 3L) / 4L - StrengthReadbackEncoding.SINT16 -> (valueCount + 1L) / 2L - } - check(invocationCount == expectedInvocationCount) - require(invocationCount in 1..Int.MAX_VALUE.toLong()) { - "$label pack invocation count is invalid: $invocationCount" - } - val submitStartNs = System.nanoTime() - GLES31.glDispatchCompute( - dispatch.groupsX, - dispatch.groupsY, - 1, - ) - GLES31.glMemoryBarrier( - GLES31.GL_SHADER_STORAGE_BARRIER_BIT or GLES31.GL_BUFFER_UPDATE_BARRIER_BIT, - ) - val submitMs = (System.nanoTime() - submitStartNs) / 1_000_000L - GLES31.glBindBufferBase(GLES31.GL_SHADER_STORAGE_BUFFER, 0, 0) - GLES31.glBindTexture(GLES31.GL_TEXTURE_2D, 0) - GLES31.glUseProgram(0) - checkGlError("queue $label SSBO pack") - return QueuedTextureReadback( - storage = storage, - mode = "compute-ssbo-pack-${dispatch.groupsX}x${dispatch.groupsY}", - targetBindMs = setupMs, - readSubmitMs = submitMs, - totalSubmitMs = (System.nanoTime() - totalStartNs) / 1_000_000L, - ).also { queued -> - PLog.i( - TAG, - "MGC Spatial strength PBO submit label=$label mode=${queued.mode} " + - "bytes=${storage.byteCount} setup=${queued.targetBindMs}ms " + - "submit=${queued.readSubmitMs}ms total=${queued.totalSubmitMs}ms", - ) - } - } - - private fun mapPixelPackBuffer( - buffer: Int, - byteCount: Int, - label: String, - ): ByteBuffer { - val startNs = System.nanoTime() - GLES30.glBindBuffer(GLES30.GL_PIXEL_PACK_BUFFER, buffer) - val mapped = GLES30.glMapBufferRange( - GLES30.GL_PIXEL_PACK_BUFFER, - 0, - byteCount, - GLES30.GL_MAP_READ_BIT, - ) as? ByteBuffer ?: error("Unable to map $label") - GLES30.glBindBuffer(GLES30.GL_PIXEL_PACK_BUFFER, 0) - PLog.i( - TAG, - "MGC Spatial strength PBO mapped label=$label bytes=$byteCount " + - "wait=${(System.nanoTime() - startNs) / 1_000_000L}ms", - ) - return mapped.order(ByteOrder.nativeOrder()).apply { - position(0) - limit(byteCount) - } - } - - private fun unmapPixelPackBuffer(buffer: Int) { - GLES30.glBindBuffer(GLES30.GL_PIXEL_PACK_BUFFER, buffer) - check(GLES30.glUnmapBuffer(GLES30.GL_PIXEL_PACK_BUFFER)) { - "MGC Spatial readback buffer contents became invalid" - } - GLES30.glBindBuffer(GLES30.GL_PIXEL_PACK_BUFFER, 0) - } - - private fun materializePreparedReadbackToHost( - prepared: PreparedTextureReadback, - label: String, - ): PreparedTextureReadback { - val queued = checkNotNull(prepared.queuedGpuReadback) { - "$label is already host-resident" - } - check(prepared.cpuBuffer == null) - val host = LargeDirectBuffer.allocate(prepared.byteCount.toLong(), label) - ?.order(ByteOrder.nativeOrder()) ?: run { - releasePixelPackBuffer(queued.storage, label) - error("Unable to allocate $label") - } - var mapped: ByteBuffer? = null - val materializeStartNs = System.nanoTime() - try { - try { - mapped = mapPixelPackBuffer( - queued.storage.buffer, - prepared.byteCount, - label, - ) - host.clear() - host.put(checkNotNull(mapped).duplicate()) - host.rewind() - } finally { - try { - if (mapped != null) { - unmapPixelPackBuffer(queued.storage.buffer) - } - } finally { - releasePixelPackBuffer(queued.storage, label) - } - } - } catch (throwable: Throwable) { - LargeDirectBuffer.free(host) - throw throwable - } - val materializeMs = (System.nanoTime() - materializeStartNs) / 1_000_000L - return PreparedTextureReadback( - byteCount = prepared.byteCount, - queuedGpuReadback = null, - cpuBuffer = host, - mode = "${prepared.mode}-host", - targetBindMs = prepared.targetBindMs, - readSubmitMs = prepared.readSubmitMs, - totalSubmitMs = prepared.totalSubmitMs + materializeMs, - ).also { - PLog.i( - TAG, - "MGC Spatial diagnostic host materialized label=$label " + - "bytes=${prepared.byteCount} took=${materializeMs}ms", - ) - } - } - private fun logLinearKernelMask( texture: Int, selectedFrameIndex: Int, @@ -6122,272 +5612,61 @@ internal class GlesMgcRawSpatialStacker( GLES30.glBindFramebuffer(GLES30.GL_FRAMEBUFFER, 0) } - private fun rgbFullTextureBytes(): Long = - outputWidth.toLong() * outputHeight * RGBA16_BYTES_PER_PIXEL - private fun rgbIirWorkingSetBytes(): Long = MgcSpatialRgbMemoryPolicy.iirWorkingSetBytes(outputWidth, outputHeight) /** - * Creates the one-upload-per-frame path. Memory estimates are advisory telemetry only: the - * driver is the authority on whether the allocation can run, so an estimate never rejects it. - * The estimates are phase-aware because fusion resources are explicitly retired before IIR. + * MGC 9.7.047 V25's Spatial RGB merge (MergeRgbRaw16F16TileSize16Halide) on the GPU, see + * [GlesMgcSpatialRgbMergeShaders]. Each burst frame's DemosaicGreenRaw16 guide feeds the same + * integer demosaic, so the three output planes share MGC's edge-directed green instead of + * reconstructing edge direction independently per color channel. */ - private fun createOnlineRgbAccumulator( - reusableRawTexture: Int, - diagnosticCapture: StrengthCapture?, - ): OnlineRgbAccumulator { - check(outputMode == MgcSpatialOutputMode.RGB) - val rawBytes = width.toLong() * height * RAW_BYTES_PER_PIXEL - val accumulatorBytes = outputWidth.toLong() * outputHeight * 16L - val chromaGuideBytes = width.toLong() * height * 2L - val diagnosticTextureBytes = diagnosticCapture?.let { capture -> - capture.geometry.fixed16Width.toLong() * capture.geometry.fixed16Height * 2L - } ?: 0L - val diagnosticPboBytes = diagnosticCapture?.let { capture -> - strengthFixed16ReadbackByteCount(capture).toLong() - } ?: 0L - // Sequential temporal scratch is allocated lazily by the first non-reference frame. - // Include two RAW-sized scratch surfaces so telemetry reflects the later capture peak. - val temporalScratchReserveBytes = maxOf( - RGB_TEXTURE_ESTIMATE_RESERVE_BYTES, - rawBytes * 2L, - ) - val temporalProjectedBytes = estimatedOwnedTextureBytes() + rawBytes + - accumulatorBytes + chromaGuideBytes + temporalScratchReserveBytes - val diagnosticProjectedBytes = accumulatorBytes + - diagnosticTextureBytes + diagnosticPboBytes + RGB_TEXTURE_ESTIMATE_RESERVE_BYTES - val assemblyProjectedBytes = accumulatorBytes + rgbFullTextureBytes() + - RGB_TEXTURE_ESTIMATE_RESERVE_BYTES - val iirProjectedBytes = rgbIirWorkingSetBytes() + RGB_TEXTURE_ESTIMATE_RESERVE_BYTES - val exportProjectedBytes = rgbFullTextureBytes() * - if (exportGpuLinearRgbSource && - gpuLinearRgbStorage == GpuLinearRgbStorage.RGBA16F - ) { - 2L - } else { - 1L - } + RGB_TEXTURE_ESTIMATE_RESERVE_BYTES - val projectedGpuBytes = maxOf( - temporalProjectedBytes, - diagnosticProjectedBytes, - assemblyProjectedBytes, - iirProjectedBytes, - exportProjectedBytes, - ) - - val secondRawTexture = createTexture( - width, - height, - GLES30.GL_R16UI, - GLES30.GL_NEAREST, - ) - val chromaGuideTexture = createTexture( - width, - height, - GLES30.GL_R16F, - GLES30.GL_NEAREST, - ) - val semanticAccumulator = createTexture( - outputWidth, - outputHeight, - GLES30.GL_RGBA16F, - GLES30.GL_NEAREST, - ) - val opponentWeightAccumulator = createTexture( - outputWidth, - outputHeight, - GLES30.GL_RGBA16F, - GLES30.GL_NEAREST, - ) - clearRgbAccumulators( - semanticAccumulator = semanticAccumulator, - opponentWeightAccumulator = opponentWeightAccumulator, - tileWidth = outputWidth, - tileHeight = outputHeight, - ) - val actualTemporalBytes = estimatedOwnedTextureBytes() - val drawBands = MgcSpatialRgbTilePlanner.planHorizontalBands( - outputWidth = outputWidth, - outputHeight = outputHeight, - maximumBandHeight = RGB_ONLINE_DRAW_BAND_HEIGHT, - ) - PLog.i( - TAG, - "MGC Spatial RGB online accumulator selected bands=${drawBands.size} " + - "drawBandHeight=$RGB_ONLINE_DRAW_BAND_HEIGHT rawSlots=2 " + - "textureBytes=$actualTemporalBytes " + - "temporalProjectedBytes=$temporalProjectedBytes " + - "diagnosticProjectedBytes=$diagnosticProjectedBytes " + - "assemblyProjectedBytes=$assemblyProjectedBytes " + - "iirProjectedBytes=$iirProjectedBytes " + - "exportProjectedBytes=$exportProjectedBytes " + - "advisoryBytes=$RGB_TEXTURE_ADVISORY_BYTES " + - "estimateExceedsAdvisory=${projectedGpuBytes > RGB_TEXTURE_ADVISORY_BYTES}", - ) - return OnlineRgbAccumulator( - semanticAccumulator = semanticAccumulator, - opponentWeightAccumulator = opponentWeightAccumulator, - chromaGuideTexture = chromaGuideTexture, - drawBands = drawBands, - rawSlots = intArrayOf(reusableRawTexture, secondRawTexture), - passWindow = GlesGpuScheduler.PassWindow( - tag = TAG, - maxInFlight = RGB_MAX_IN_FLIGHT_PASSES, - ), - projectedGpuBytes = projectedGpuBytes, - // Slot zero may still contain the evaluated Bento frame. Start with the new slot. - nextRawSlot = 1, - ) - } - - private fun contributeOnlineRgbFrame( - accumulator: OnlineRgbAccumulator, - frame: RgbMergeFrame, - rawTexture: Int, - label: String, - ) { - val rawResource = GlesGpuScheduler.textureResource(rawTexture) - val fullRaw = MgcSpatialRgbRect(0, 0, width, height) - renderRgbChromaGuide( - frame = frame, - rawTexture = rawTexture, - rawTextureOrigin = fullRaw, - sourceRegion = fullRaw, - outputTexture = accumulator.chromaGuideTexture, - ) - accumulator.drawBands.forEach { band -> - accumulator.passWindow.beginPass( - label = "MGC RGB online $label band ${band.index}", - reads = longArrayOf(rawResource), - ) - try { - renderRgbFrameContribution( - frame = frame, - rawTexture = rawTexture, - rawTextureOrigin = fullRaw, - sourceRegion = fullRaw, - outputCores = listOf(band.outputCore), - chromaGuideRegionTexture = accumulator.chromaGuideTexture, - semanticAccumulator = accumulator.semanticAccumulator, - opponentWeightAccumulator = accumulator.opponentWeightAccumulator, - accumulatorIsFullOutput = true, - ) - } finally { - accumulator.passWindow.endPass() - } - } - accumulator.contributedFrames += 1 - } - - /** - * Executes MGC 9.7.047 V25's complete Spatial RGB Halide AOT. In particular, this call keeps - * DemosaicGreenRaw16 inside the original pipeline; the three output planes therefore share - * MGC's edge-directed green guide and adaptive kernel geometry instead of reconstructing edge - * direction independently per color channel. - */ - private fun renderOriginalAotRgbMerge( + private fun renderSpatialRgbMerge( frames: List, images: List, outputExposureScale: Float, ultrashortWeight: Int, mergeSharpness: Float, capture: StrengthCapture, - preparedAlignment: PreparedTextureReadback, - preparedRejection: PreparedTextureReadback, ): RgbMergeOutput { check(outputMode == MgcSpatialOutputMode.RGB) - check(normalizeAotRgbProgram != 0) { - "MGC Spatial V25 AOT output program is not initialized" + check(spatialRgbAccumulateProgram != 0 && spatialRgbResolveProgram != 0) { + "MGC Spatial V25 RGB merge programs are not initialized" } require(frames.isNotEmpty() && frames.size == capture.frameCount) require(frames.all { it.imageIndex in images.indices }) require(outputExposureScale.isFinite() && outputExposureScale > 0f) require(mergeSharpness.isFinite() && mergeSharpness >= 0f) check(capture.geometry.imageWidth == width && capture.geometry.imageHeight == height && - capture.geometry.fixed16Width == rgbAotStorageWidth && - capture.geometry.fixed16Height == rgbAotStorageHeight) { - "MGC Spatial RGB AOT geometry ${capture.geometry.fixed16Width}x" + - "${capture.geometry.fixed16Height} does not match " + - "native=${width}x$height storage=${rgbAotStorageWidth}x$rgbAotStorageHeight" + capture.alignmentWidth == ceilDiv(width, GlesMgcSpatialRgbMergeShaders.TILE_SIZE) && + capture.alignmentHeight == ceilDiv(height, GlesMgcSpatialRgbMergeShaders.TILE_SIZE)) { + "MGC Spatial RGB alignment ${capture.alignmentWidth}x${capture.alignmentHeight} " + + "does not tile native=${width}x$height" } - val alignment = checkNotNull(preparedAlignment.cpuBuffer) { - "MGC Spatial RGB AOT alignment is not host-resident" - }.duplicate().order(ByteOrder.nativeOrder()).apply { - position(0) - limit(preparedAlignment.byteCount) - } - val rejection = checkNotNull(preparedRejection.cpuBuffer) { - "MGC Spatial RGB AOT rejection is not host-resident" - }.duplicate().order(ByteOrder.nativeOrder()).apply { - position(0) - limit(preparedRejection.byteCount) - } - val rawPlanes = frames.map { frame -> - images[frame.imageIndex].planes.firstOrNull() - ?: error("MGC Spatial RGB frame ${frame.imageIndex} has no RAW plane") - } - rawPlanes.forEachIndexed { index, plane -> - require(plane.pixelStride == RAW_BYTES_PER_PIXEL) { - "MGC Spatial RGB AOT frame $index pixel stride=${plane.pixelStride}, expected 2" - } - require(plane.rowStride >= sourceBounds.right * RAW_BYTES_PER_PIXEL) { - "MGC Spatial RGB AOT frame $index row stride=${plane.rowStride}, " + - "crop=$sourceBounds" - } - } - val rawBuffers = Array(rawPlanes.size) { index -> - rawPlanes[index].buffer.duplicate().order(ByteOrder.nativeOrder()).also { buffer -> - require(buffer.isDirect) { "MGC Spatial RGB AOT RAW frame $index is not direct" } - } - } - val rawOffsets = IntArray(rawBuffers.size) { index -> rawBuffers[index].position() } - rawOffsets.indices.forEach { index -> - rawOffsets[index] += sourceBounds.top * rawPlanes[index].rowStride + - sourceBounds.left * RAW_BYTES_PER_PIXEL - } - val rawRowStrides = IntArray(rawPlanes.size) { index -> rawPlanes[index].rowStride } val referenceBlack = frames.first().calibration.blackLevels val sourceCameraWhite = checkNotNull(cameraWhite) { "Spatial RGB requires the source CameraWhite color solution" } require(sourceCameraWhite.size == 3 && sourceCameraWhite.all { it.isFinite() && it > 0f && it <= 1f }) - // AOT samples are black-subtracted RAW codes times overallGain, stored as F16/Q14. + // Merged samples are black-subtracted RAW codes times overallGain, stored as F16/Q14. // Its reference white is therefore not 16384 (e.g. RAW10 with black=64 gives // 15344). Use one scalar for the color-spec vector so its neutral ratios survive. val referenceWhite = (sensorWhiteLevel - 0.5f * (referenceBlack[1] + referenceBlack[2])) * sabreResolveRawScale / 16384f require(referenceWhite.isFinite() && referenceWhite > 0f) - val aotCameraWhite = FloatArray(3) { sourceCameraWhite[it] * referenceWhite } - val inputBlackRgb = floatArrayOf( - referenceBlack[0], - 0.5f * (referenceBlack[1] + referenceBlack[2]), - referenceBlack[3], - ) - val inputGains = FloatArray(frames.size) { index -> - frames[index].calibration.inputGain - } - val aotByteCount = strengthFixed16ReadbackByteCount(capture) + val mergeCameraWhite = FloatArray(3) { sourceCameraWhite[it] * referenceWhite } val outputBytes = outputWidth.toLong() * outputHeight * 3L * Short.SIZE_BYTES require(outputBytes in 1..Int.MAX_VALUE.toLong()) val fullOutput = MgcSpatialRgbRect(0, 0, outputWidth, outputHeight) val fullOutputTile = MgcSpatialRgbTile(index = 0, outputCore = fullOutput) - var aotPlanar: ByteBuffer? = null var cpuOutput: ByteBuffer? = null - var diagnosticFixed16: PreparedTextureReadback? = null var gpuOutput = 0 var postprocessedUi = 0 val completionRecorder = GlesGpuCompletion.StackTimelineRecorder() var completionTimeline: GpuStackCompletionTimeline? = null try { - aotPlanar = LargeDirectBuffer.allocate( - aotByteCount.toLong(), - "MGC V25 Spatial RGB planar F16/Q14", - )?.order(ByteOrder.nativeOrder()) ?: error( - "Unable to allocate MGC V25 Spatial RGB planar output", - ) if (!exportGpuLinearRgbSource) { cpuOutput = LargeDirectBuffer.allocate( outputBytes, @@ -6396,62 +5675,34 @@ internal class GlesMgcRawSpatialStacker( "Unable to allocate MGC V25 Spatial RGB16 output", ) } - val aotStartNs = System.nanoTime() - MgcSpatialRgbMerger.merge( - rawBuffers = rawBuffers, - rawOffsets = rawOffsets, - rawRowStrides = rawRowStrides, - alignment = alignment, - alignmentWidth = capture.alignmentWidth, - alignmentHeight = capture.alignmentHeight, - rejection = rejection, - rejectionWidth = capture.rejectionWidth, - rejectionHeight = capture.rejectionHeight, - frameWeights = capture.frameWeights, - whiteBalanceGains = calculationWhiteBalance, - inputBlackLevelsRgb = inputBlackRgb, - inputBlackLevelsRggb = referenceBlack, - inputGains = inputGains, - overallGain = sabreResolveRawScale, - mergeSharpness = mergeSharpness, - kernelSigmas = capture.kernelSigmas, - rawWidth = width, - rawHeight = height, - outputWidth = width, - outputHeight = height, - outputStorageWidth = rgbAotStorageWidth, - outputStorageHeight = rgbAotStorageHeight, - cfaPattern = cfaPattern, - outputPlanarF16 = checkNotNull(aotPlanar), - ) - val aotMs = elapsedMs(aotStartNs) - val chromaPostprocessor = checkNotNull(rgbChromaPostprocessor) { "MGC Spatial RGB chroma postprocessor is not initialized" } chromaPostprocessor.initStorage(listOf(fullOutputTile)) val lensShadingTexture = createLensShadingTexture() - uploadAndNormalizeOriginalAotRgb( - planarF16 = checkNotNull(aotPlanar), + val mergeStartNs = System.nanoTime() + mergeSpatialRgbFrames( + frames = frames, + images = images, + mergeSharpness = mergeSharpness, + capture = capture, + referenceBlack = referenceBlack, lensShadingTexture = lensShadingTexture, target = chromaPostprocessor.normalizationTargetTexture(), outputExposureScale = outputExposureScale, - cameraWhite = aotCameraWhite, + cameraWhite = mergeCameraWhite, ultrashortWeight = ultrashortWeight, ) + val mergeMs = elapsedMs(mergeStartNs) PLog.i(TAG, "MGC Spatial CameraWhite source=${sourceCameraWhite.contentToString()} " + - "aot=${aotCameraWhite.contentToString()} normalization=$outputExposureScale " + + "merge=${mergeCameraWhite.contentToString()} normalization=$outputExposureScale " + "referenceFallbackWhiteScale=$outputExposureScale " + "hasShort=${ultrashortWeight != 0} stage=before-rgb16") chromaPostprocessor.markTileWritten(fullOutputTile) - // The GL upload no longer reads client memory after glTexSubImage2D returns. - LargeDirectBuffer.free(aotPlanar) - aotPlanar = null - releaseRgbFusionPhaseTextures( retainedTexture = chromaPostprocessor.normalizationTargetTexture(), - label = "V25 AOT", + label = "V25 merge", ) GlesGpuScheduler.memoryBarrier() val chromaResult = chromaPostprocessor.process( @@ -6472,7 +5723,7 @@ internal class GlesMgcRawSpatialStacker( postprocessedUi.also { postprocessedUi = 0 } } else { GlesGpuCompletion.awaitSubmittedWork( - label = "MGC Spatial V25 AOT IIR-to-float handoff", + label = "MGC Spatial V25 merge IIR-to-float handoff", checkGlError = ::checkGlError, ) createTexture( @@ -6492,7 +5743,7 @@ internal class GlesMgcRawSpatialStacker( completionTimeline = completionRecorder.finish() if (completionTimeline == null) { GlesGpuCompletion.awaitSubmittedWork( - label = "MGC Spatial V25 AOT RGB export", + label = "MGC Spatial V25 merge RGB export", checkGlError = ::checkGlError, ) } @@ -6500,18 +5751,16 @@ internal class GlesMgcRawSpatialStacker( } PLog.i( TAG, - "MGC Spatial V25 RGB AOT frames=${frames.size} " + + "MGC Spatial V25 RGB merge frames=${frames.size} " + "native=${width}x$height " + - "storage=${rgbAotStorageWidth}x$rgbAotStorageHeight " + "output=${outputWidth}x$outputHeight rawScale=$sabreResolveRawScale " + - "mergeSharpness=$mergeSharpness aot=${aotMs}ms " + + "mergeSharpness=$mergeSharpness merge=${mergeMs}ms " + "colorNoiseIir=${chromaResult.chromaSubmissionMs}ms " + "chromaFinal=${chromaResult.finalSubmissionMs}ms", ) return RgbMergeOutput( cpuBuffer = cpuOutput, gpuTexture = gpuOutput, - diagnosticFixed16 = diagnosticFixed16, completionTimeline = completionTimeline, ) } catch (throwable: Throwable) { @@ -6523,924 +5772,11 @@ internal class GlesMgcRawSpatialStacker( if (gpuOutput != 0 && !textures.contains(gpuOutput)) { GLES30.glDeleteTextures(1, intArrayOf(gpuOutput), 0) } - LargeDirectBuffer.free(aotPlanar) - LargeDirectBuffer.free(diagnosticFixed16?.cpuBuffer) LargeDirectBuffer.free(cpuOutput) throw throwable } } - private fun finishOnlineRgbMerge( - accumulator: OnlineRgbAccumulator, - outputExposureScale: Float, - diagnosticCapture: StrengthCapture?, - ): RgbMergeOutput { - require(outputExposureScale.isFinite() && outputExposureScale > 0f) - val fullOutput = MgcSpatialRgbRect(0, 0, outputWidth, outputHeight) - val fullOutputTile = MgcSpatialRgbTile(index = 0, outputCore = fullOutput) - val lensShadingTexture = createLensShadingTexture() - var gpuOutput = 0 - var postprocessedUi = 0 - val outputBytes = outputWidth.toLong() * outputHeight * 3L * Short.SIZE_BYTES - require(outputBytes in 1..Int.MAX_VALUE.toLong()) - val cpuOutput = if (!exportGpuLinearRgbSource) { - LargeDirectBuffer.allocate(outputBytes, "MGC Spatial online RGB16 output") - ?.order(ByteOrder.nativeOrder()) ?: error( - "Unable to allocate MGC Spatial online RGB16 output", - ) - } else { - null - } - var diagnosticStorage: PixelPackBuffer? = null - var diagnosticFramebuffer = 0 - var diagnosticFixed16Texture = 0 - var diagnosticFixed16: PreparedTextureReadback? = null - val completionRecorder = GlesGpuCompletion.StackTimelineRecorder() - var completionTimeline: GpuStackCompletionTimeline? = null - try { - val chromaPostprocessor = checkNotNull(rgbChromaPostprocessor) { - "MGC Spatial RGB chroma postprocessor is not initialized" - } - diagnosticFixed16 = diagnosticCapture?.let { capture -> - diagnosticFixed16Texture = createTexture( - capture.geometry.fixed16Width, - capture.geometry.fixed16Height, - GLES30.GL_R16I, - GLES30.GL_NEAREST, - ) - diagnosticFramebuffer = createFramebuffer() - GLES30.glBindFramebuffer(GLES30.GL_FRAMEBUFFER, diagnosticFramebuffer) - GLES30.glFramebufferTexture2D( - GLES30.GL_FRAMEBUFFER, - GLES30.GL_COLOR_ATTACHMENT0, - GLES30.GL_TEXTURE_2D, - diagnosticFixed16Texture, - 0, - ) - GLES30.glDrawBuffers(1, intArrayOf(GLES30.GL_COLOR_ATTACHMENT0), 0) - check(GLES30.glCheckFramebufferStatus(GLES30.GL_FRAMEBUFFER) == - GLES30.GL_FRAMEBUFFER_COMPLETE) { - "MGC online RGB Fixed16 framebuffer is incomplete" - } - GLES30.glBindFramebuffer(GLES30.GL_FRAMEBUFFER, 0) - diagnosticStorage = allocatePixelPackBuffer( - strengthFixed16ReadbackByteCount(capture), - "MGC Spatial online RGB Fixed16 source", - ) - val timing = packRgbFixed16TileReadback( - capture = capture, - semanticAccumulator = accumulator.semanticAccumulator, - opponentWeightAccumulator = accumulator.opponentWeightAccumulator, - outputCore = fullOutput, - fixed16Texture = diagnosticFixed16Texture, - diagnosticFramebuffer = diagnosticFramebuffer, - storage = checkNotNull(diagnosticStorage), - ) - val queued = QueuedTextureReadback( - storage = checkNotNull(diagnosticStorage), - mode = "online-full-accumulator-pbo-rgb-planar-q14", - targetBindMs = timing.setupNs / 1_000_000L, - readSubmitMs = timing.dispatchNs / 1_000_000L, - totalSubmitMs = (timing.setupNs + timing.dispatchNs) / 1_000_000L, - ) - PreparedTextureReadback( - byteCount = strengthFixed16ReadbackByteCount(capture), - queuedGpuReadback = queued, - cpuBuffer = null, - mode = queued.mode, - targetBindMs = queued.targetBindMs, - readSubmitMs = queued.readSubmitMs, - totalSubmitMs = queued.totalSubmitMs, - ) - } - - // Finish the full-size diagnostic while only the fusion accumulators are live. Its - // texture and PBO must be gone before the assembled RGB/IIR surfaces are allocated. - diagnosticFixed16 = diagnosticFixed16?.let { prepared -> - try { - materializePreparedReadbackToHost( - prepared = prepared, - label = "MGC Spatial online RGB Fixed16 host source", - ) - } finally { - diagnosticStorage = null - } - } - detachFramebufferColorAttachment(diagnosticFramebuffer) - if (diagnosticFixed16Texture != 0) { - releaseOwnedTexture( - diagnosticFixed16Texture, - "online RGB Fixed16 diagnostic texture", - ) - diagnosticFixed16Texture = 0 - } - - chromaPostprocessor.initStorage(listOf(fullOutputTile)) - renderRgbNormalizedTile( - semanticAccumulator = accumulator.semanticAccumulator, - opponentWeightAccumulator = accumulator.opponentWeightAccumulator, - lensShadingTexture = lensShadingTexture, - outputCore = fullOutput, - target = chromaPostprocessor.normalizationTargetTexture(), - targetIsFullOutput = true, - outputExposureScale = outputExposureScale, - ) - chromaPostprocessor.markTileWritten(fullOutputTile) - accumulator.passWindow.drain("MGC RGB online fusion-to-IIR handoff") - releaseRgbFusionPhaseTextures( - retainedTexture = chromaPostprocessor.normalizationTargetTexture(), - label = "online", - ) - GlesGpuScheduler.memoryBarrier() - val chromaResult = chromaPostprocessor.process( - obtainOutputBuffer = { checkNotNull(cpuOutput) }, - deferFullSizeReadback = exportGpuLinearRgbSource, - onFinalSubmitted = if (exportGpuLinearRgbSource) { - { completionRecorder.mark(GpuStackCompletionStage.CHROMA_POSTPROCESS) } - } else { - null - }, - ) - postprocessedUi = chromaResult.exportedTextureId - if (exportGpuLinearRgbSource) { - check(postprocessedUi != 0) { - "MGC Spatial RGB chroma did not export its filtered texture" - } - gpuOutput = if (gpuLinearRgbStorage == GpuLinearRgbStorage.RGBA16UI) { - postprocessedUi.also { postprocessedUi = 0 } - } else { - // Ensure the deleted IIR work surfaces are reclaimable before allocating the - // float export texture; otherwise drivers may transiently retain four surfaces. - GlesGpuCompletion.awaitSubmittedWork( - label = "MGC Spatial RGB IIR-to-float handoff", - checkGlError = ::checkGlError, - ) - createTexture( - outputWidth, - outputHeight, - GLES30.GL_RGBA16F, - GLES30.GL_NEAREST, - ).also { target -> - renderRgb16ToFloat(postprocessedUi, target) - GLES30.glDeleteTextures(1, intArrayOf(postprocessedUi), 0) - postprocessedUi = 0 - } - } - } - - val gpuDeclaredBytes = estimatedOwnedTextureBytes() + - if (gpuOutput != 0 && !textures.contains(gpuOutput)) { - rgbFullTextureBytes() - } else { - 0L - } - if (gpuOutput != 0) { - completionRecorder.mark(GpuStackCompletionStage.FINAL_EXPORT) - completionTimeline = completionRecorder.finish() - if (completionTimeline == null) { - GlesGpuCompletion.awaitSubmittedWork( - label = "MGC Spatial online RGB export", - checkGlError = ::checkGlError, - ) - } - if (textures.remove(gpuOutput)) { - textureSpecs.remove(gpuOutput) - } - } - PLog.i( - TAG, - "MGC Spatial RGB online RAW uploads=${accumulator.rawUploadCount} " + - "bytes=${accumulator.rawUploadBytes} " + - "submit=${accumulator.rawUploadNs / 1_000_000L}ms " + - "frames=${accumulator.contributedFrames} drawBands=${accumulator.drawBands.size} " + - "colorNoiseIir=${chromaResult.chromaSubmissionMs}ms " + - "chromaFinal=${chromaResult.finalSubmissionMs}ms " + - "gpuDeclaredBytes=$gpuDeclaredBytes " + - "projectedGpuBytes=${accumulator.projectedGpuBytes}", - ) - return RgbMergeOutput( - cpuBuffer = cpuOutput, - gpuTexture = gpuOutput, - diagnosticFixed16 = diagnosticFixed16, - completionTimeline = completionTimeline, - ) - } catch (throwable: Throwable) { - completionTimeline?.releasePending() - completionRecorder.releasePending() - diagnosticStorage?.let { storage -> - releasePixelPackBuffer(storage, "failed MGC Spatial online RGB Fixed16") - } - if (postprocessedUi != 0) { - GLES30.glDeleteTextures(1, intArrayOf(postprocessedUi), 0) - } - if (gpuOutput != 0 && !textures.contains(gpuOutput)) { - GLES30.glDeleteTextures(1, intArrayOf(gpuOutput), 0) - } - LargeDirectBuffer.free(diagnosticFixed16?.cpuBuffer) - LargeDirectBuffer.free(cpuOutput) - throw throwable - } - } - - private fun createRgbBandPlan( - frames: List, - diagnosticCapture: StrengthCapture?, - maximumBandHeight: Int, - ): RgbBandPlan { - val bands = MgcSpatialRgbTilePlanner.planHorizontalBands( - outputWidth = outputWidth, - outputHeight = outputHeight, - maximumBandHeight = maximumBandHeight, - ) - val work = bands.map { band -> - band to frames.map { frame -> - val sourceRegion = MgcSpatialRgbTilePlanner.sourceRegion( - tile = band, - rawWidth = width, - rawHeight = height, - outputWidth = outputWidth, - outputHeight = outputHeight, - flowBounds = frame.flowBounds, - ) - RgbTileFrameRegion( - frame = frame, - sourceRegion = sourceRegion, - uploadRegion = expandRgbRawRegion( - sourceRegion, - RGB_CHROMA_GUIDE_RAW_RADIUS, - ), - ) - } - } - val maximumOutputWidth = bands.maxOf { it.outputCore.width } - val maximumOutputHeight = bands.maxOf { it.outputCore.height } - val diagnosticPaddingWidth = diagnosticCapture?.let { capture -> - capture.geometry.fixed16Width - outputWidth - } ?: 0 - val diagnosticPaddingHeight = diagnosticCapture?.let { capture -> - capture.geometry.fixed16Height - outputHeight - } ?: 0 - val maximumDiagnosticWidth = bands.maxOf { band -> - band.outputCore.width + - if (band.outputCore.right == outputWidth) diagnosticPaddingWidth else 0 - } - val maximumDiagnosticHeight = bands.maxOf { band -> - band.outputCore.height + - if (band.outputCore.bottom == outputHeight) diagnosticPaddingHeight else 0 - } - val maximumSourceWidth = work.maxOf { (_, regions) -> - regions.maxOf { it.sourceRegion.width } - } - val maximumSourceHeight = work.maxOf { (_, regions) -> - regions.maxOf { it.sourceRegion.height } - } - val maximumUploadWidth = work.maxOf { (_, regions) -> - regions.maxOf { it.uploadRegion.width } - } - val maximumUploadHeight = work.maxOf { (_, regions) -> - regions.maxOf { it.uploadRegion.height } - } - val rawWindowBytes = maximumUploadWidth.toLong() * maximumUploadHeight * - RAW_BYTES_PER_PIXEL * RGB_RAW_WINDOW_SLOTS - val chromaGuideBytes = maximumSourceWidth.toLong() * maximumSourceHeight * 2L - val accumulatorBytes = maximumOutputWidth.toLong() * maximumOutputHeight * 16L - val assembledRgbBytes = rgbFullTextureBytes() - val diagnosticTextureBytes = if (diagnosticCapture != null) { - maximumDiagnosticWidth.toLong() * maximumDiagnosticHeight * 2L - } else { - 0L - } - val diagnosticPboBytes = if (diagnosticCapture != null) { - maximumDiagnosticWidth.toLong() * maximumDiagnosticHeight * 3L * - Short.SIZE_BYTES * minOf(RGB_DIAGNOSTIC_PBO_SLOTS, bands.size) - } else { - 0L - } - val projectedGpuBytes = estimatedOwnedTextureBytes() + rawWindowBytes + - chromaGuideBytes + accumulatorBytes + assembledRgbBytes + - diagnosticTextureBytes + diagnosticPboBytes + RGB_TEXTURE_ESTIMATE_RESERVE_BYTES - return RgbBandPlan( - bands = bands, - work = work, - maximumOutputWidth = maximumOutputWidth, - maximumOutputHeight = maximumOutputHeight, - maximumDiagnosticWidth = maximumDiagnosticWidth, - maximumDiagnosticHeight = maximumDiagnosticHeight, - maximumSourceWidth = maximumSourceWidth, - maximumSourceHeight = maximumSourceHeight, - maximumUploadWidth = maximumUploadWidth, - maximumUploadHeight = maximumUploadHeight, - projectedGpuBytes = projectedGpuBytes, - ) - } - - private fun renderRgbMerge( - frames: List, - images: List, - outputExposureScale: Float, - diagnosticCapture: StrengthCapture?, - ): RgbMergeOutput { - check(outputMode == MgcSpatialOutputMode.RGB) - check(mergeRgbProgram != 0 && normalizeRgbProgram != 0) - require(frames.isNotEmpty()) - require(frames.all { it.imageIndex in images.indices }) - require(outputExposureScale.isFinite() && outputExposureScale > 0f) - diagnosticCapture?.let { capture -> - check(capture.outputMode == MgcSpatialOutputMode.RGB) - check( - capture.geometry.imageWidth == outputWidth && - capture.geometry.imageHeight == outputHeight - ) { - "MGC RGB diagnostic geometry ${capture.geometry.imageWidth}x" + - "${capture.geometry.imageHeight} does not match output ${outputWidth}x$outputHeight" - } - } - val bandPlans = rgbBandHeightCandidates().map { maximumBandHeight -> - createRgbBandPlan( - frames = frames, - diagnosticCapture = diagnosticCapture, - maximumBandHeight = maximumBandHeight, - ) - } - val bandPlan = bandPlans[ - MgcSpatialRgbMemoryPolicy.selectAdvisoryPlanIndex( - projectedBytes = bandPlans.map(RgbBandPlan::projectedGpuBytes), - advisoryBytes = RGB_TEXTURE_ADVISORY_BYTES, - ) - ] - val bands = bandPlan.bands - val work = bandPlan.work - val maximumOutputWidth = bandPlan.maximumOutputWidth - val maximumOutputHeight = bandPlan.maximumOutputHeight - val maximumDiagnosticWidth = bandPlan.maximumDiagnosticWidth - val maximumDiagnosticHeight = bandPlan.maximumDiagnosticHeight - val maximumSourceWidth = bandPlan.maximumSourceWidth - val maximumSourceHeight = bandPlan.maximumSourceHeight - val maximumUploadWidth = bandPlan.maximumUploadWidth - val maximumUploadHeight = bandPlan.maximumUploadHeight - val rawBandTextures = List(RGB_RAW_WINDOW_SLOTS) { - createTexture( - maximumUploadWidth, - maximumUploadHeight, - GLES30.GL_R16UI, - GLES30.GL_NEAREST, - ) - } - val chromaGuideRegionTexture = createTexture( - maximumSourceWidth, - maximumSourceHeight, - GLES30.GL_R16F, - GLES30.GL_NEAREST, - ) - val semanticAccumulator = createTexture( - maximumOutputWidth, - maximumOutputHeight, - GLES30.GL_RGBA16F, - GLES30.GL_NEAREST, - ) - val opponentWeightAccumulator = createTexture( - maximumOutputWidth, - maximumOutputHeight, - GLES30.GL_RGBA16F, - GLES30.GL_NEAREST, - ) - val lensShadingTexture = createLensShadingTexture() - var gpuOutput = 0 - var postprocessedUi = 0 - val outputBytes = outputWidth.toLong() * outputHeight.toLong() * 3L * Short.SIZE_BYTES - require(outputBytes <= Int.MAX_VALUE) { - "MGC Spatial RGB CPU output is too large: $outputBytes bytes" - } - val cpuOutput = if (!exportGpuLinearRgbSource) { - LargeDirectBuffer.allocate( - outputBytes, - "MGC Spatial fused linear RGB16", - )?.order(ByteOrder.nativeOrder()) ?: error( - "Unable to allocate MGC Spatial RGB16 output", - ) - } else { - null - } - val diagnosticTexture = if (diagnosticCapture != null) { - createTexture( - maximumDiagnosticWidth, - maximumDiagnosticHeight, - GLES30.GL_R16I, - GLES30.GL_NEAREST, - ) - } else { - 0 - } - val diagnosticFramebuffer = if (diagnosticCapture != null) createFramebuffer() else 0 - val diagnosticBandByteCount = ( - maximumDiagnosticWidth.toLong() * maximumDiagnosticHeight * 3L * Short.SIZE_BYTES - ).also { bytes -> require(bytes in 1..Int.MAX_VALUE.toLong()) } - .toInt() - val diagnosticStorages = if (diagnosticCapture != null) { - // A second slot only overlaps readback with useful work when another band exists. - // Keeping one full-frame PBO makes the one-band fast path fit the same hard budget. - List(minOf(RGB_DIAGNOSTIC_PBO_SLOTS, bands.size)) { slot -> - allocatePixelPackBuffer( - diagnosticBandByteCount, - "MGC Spatial RGB Fixed16 band slot $slot", - ) - } - } else { - emptyList() - } - val diagnosticHostBuffer = diagnosticCapture?.let { capture -> - val byteCount = strengthFixed16ReadbackByteCount(capture) - LargeDirectBuffer.allocate( - byteCount.toLong(), - "MGC Spatial RGB Fixed16 host source", - )?.order(ByteOrder.nativeOrder()) ?: error( - "Unable to allocate MGC Spatial RGB Fixed16 host source", - ) - } - val pendingDiagnosticBands = arrayOfNulls( - diagnosticStorages.size, - ) - if (diagnosticCapture != null) { - GLES30.glBindFramebuffer(GLES30.GL_FRAMEBUFFER, diagnosticFramebuffer) - GLES30.glFramebufferTexture2D( - GLES30.GL_FRAMEBUFFER, - GLES30.GL_COLOR_ATTACHMENT0, - GLES30.GL_TEXTURE_2D, - diagnosticTexture, - 0, - ) - GLES30.glDrawBuffers(1, intArrayOf(GLES30.GL_COLOR_ATTACHMENT0), 0) - val status = GLES30.glCheckFramebufferStatus(GLES30.GL_FRAMEBUFFER) - check(status == GLES30.GL_FRAMEBUFFER_COMPLETE) { - "MGC RGB Fixed16 diagnostic framebuffer incomplete: 0x${status.toString(16)}" - } - GLES30.glBindFramebuffer(GLES30.GL_FRAMEBUFFER, 0) - applyRawRenderState() - checkGlError("MGC Spatial RGB post-output diagnostic resources") - } - PLog.i( - TAG, - "MGC Spatial RGB streamed-raw " + - "bands=${bands.size} rawWindowSlots=${rawBandTextures.size} " + - "rawWindow=${maximumUploadWidth}x$maximumUploadHeight " + - "rawWindowBytes=" + - "${maximumUploadWidth.toLong() * maximumUploadHeight * RAW_BYTES_PER_PIXEL * rawBandTextures.size} " + - "maxOutput=${maximumOutputWidth}x$maximumOutputHeight " + - "maxChromaGuide=${maximumSourceWidth}x$maximumSourceHeight " + - "frames=${frames.size} reconstruction=joint-G/R-G/B-G " + - "chromaGuide=separate-pass diagnosticPack=${when { - diagnosticCapture == null -> "disabled" - diagnosticStorages.size == 1 -> "one-slot-band-pbo-to-host" - else -> "two-slot-band-pbo-to-host" - }}", - ) - var diagnosticSetupNs = 0L - var diagnosticDispatchNs = 0L - var rawBandUploadNs = 0L - var rawBandUploadBytes = 0L - var rawBandUploadCount = 0 - val passWindow = GlesGpuScheduler.PassWindow( - tag = TAG, - maxInFlight = RGB_MAX_IN_FLIGHT_PASSES, - ) - val completionRecorder = GlesGpuCompletion.StackTimelineRecorder() - var diagnosticStoragesReleased = false - val gpuDeclaredBytes = estimatedOwnedTextureBytes() + - diagnosticBandByteCount.toLong() * diagnosticStorages.size - PLog.i( - TAG, - "MGC Spatial RGB reconstruction textureBytes=${estimatedOwnedTextureBytes()} " + - "diagnosticPboBytes=" + - "${diagnosticBandByteCount.toLong() * diagnosticStorages.size} " + - "diagnosticHostBytes=${diagnosticHostBuffer?.capacity() ?: 0} " + - "gpuDeclaredBytes=$gpuDeclaredBytes " + - "projectedGpuBytes=${bandPlan.projectedGpuBytes} " + - "advisoryBytes=$RGB_TEXTURE_ADVISORY_BYTES " + - "estimateExceedsAdvisory=" + - "${bandPlan.projectedGpuBytes > RGB_TEXTURE_ADVISORY_BYTES} " + - "bandHeight=${bands.maxOf { it.outputCore.height }} " + - "maxInFlight=$RGB_MAX_IN_FLIGHT_PASSES", - ) - - try { - val chromaPostprocessor = checkNotNull(rgbChromaPostprocessor) { - "MGC Spatial RGB chroma postprocessor is not initialized" - } - chromaPostprocessor.initStorage(bands) - for ((band, frameRegions) in work) { - val diagnosticSlotIndex = if (diagnosticStorages.isEmpty()) { - -1 - } else { - band.index % diagnosticStorages.size - } - if (diagnosticSlotIndex >= 0) { - pendingDiagnosticBands[diagnosticSlotIndex]?.let { pending -> - passWindow.awaitResources( - label = "MGC RGB diagnostic band ${pending.outputCore.top} host copy", - resources = longArrayOf( - GlesGpuScheduler.bufferResource(pending.storage.buffer), - ), - ) - copyRgbFixed16BandToHost( - capture = checkNotNull(diagnosticCapture), - pending = pending, - destination = checkNotNull(diagnosticHostBuffer), - ) - pendingDiagnosticBands[diagnosticSlotIndex] = null - } - } - frameRegions.forEachIndexed { framePosition, frameRegion -> - if (framePosition == 0) { - clearRgbAccumulators( - semanticAccumulator = semanticAccumulator, - opponentWeightAccumulator = opponentWeightAccumulator, - tileWidth = band.outputCore.width, - tileHeight = band.outputCore.height, - ) - } - val rawBandTexture = rawBandTextures[framePosition % rawBandTextures.size] - val rawResource = GlesGpuScheduler.textureResource(rawBandTexture) - passWindow.beginPass( - label = "MGC RGB band ${band.index} frame $framePosition", - reads = longArrayOf(rawResource), - writes = longArrayOf(rawResource), - ) - try { - val uploadStartNs = System.nanoTime() - uploadRawRegion( - image = images[frameRegion.frame.imageIndex], - texture = rawBandTexture, - region = frameRegion.uploadRegion, - label = - "RGB band ${band.index} frame ${frameRegion.frame.imageIndex}", - ) - rawBandUploadNs += System.nanoTime() - uploadStartNs - rawBandUploadBytes += frameRegion.uploadRegion.width.toLong() * - frameRegion.uploadRegion.height * RAW_BYTES_PER_PIXEL - rawBandUploadCount += 1 - renderRgbChromaGuide( - frame = frameRegion.frame, - rawTexture = rawBandTexture, - rawTextureOrigin = frameRegion.uploadRegion, - sourceRegion = frameRegion.sourceRegion, - outputTexture = chromaGuideRegionTexture, - ) - renderRgbFrameContribution( - frame = frameRegion.frame, - rawTexture = rawBandTexture, - rawTextureOrigin = frameRegion.uploadRegion, - sourceRegion = frameRegion.sourceRegion, - outputCores = listOf(band.outputCore), - chromaGuideRegionTexture = chromaGuideRegionTexture, - semanticAccumulator = semanticAccumulator, - opponentWeightAccumulator = opponentWeightAccumulator, - ) - } finally { - passWindow.endPass() - } - } - val diagnosticStorage = diagnosticSlotIndex.takeIf { it >= 0 }?.let { - diagnosticStorages[it] - } - passWindow.beginPass( - label = "MGC RGB band ${band.index} normalize", - writes = longArrayOf( - GlesGpuScheduler.bufferResource(diagnosticStorage?.buffer ?: 0), - ), - ) - var pendingDiagnosticBand: PendingRgbDiagnosticBand? = null - try { - renderRgbNormalizedTile( - semanticAccumulator = semanticAccumulator, - opponentWeightAccumulator = opponentWeightAccumulator, - lensShadingTexture = lensShadingTexture, - outputCore = band.outputCore, - target = chromaPostprocessor.normalizationTargetTexture(), - targetIsFullOutput = true, - outputExposureScale = outputExposureScale, - ) - chromaPostprocessor.markTileWritten(band) - GlesGpuScheduler.yieldToUiRenderer() - diagnosticCapture?.let { capture -> - // The production output for this band has already been submitted. The - // accumulator remains valid until the next band begins with an explicit - // clear, so pack diagnostics now without replaying any frame contribution. - val timing = packRgbFixed16TileReadback( - capture = capture, - semanticAccumulator = semanticAccumulator, - opponentWeightAccumulator = opponentWeightAccumulator, - outputCore = band.outputCore, - fixed16Texture = diagnosticTexture, - diagnosticFramebuffer = diagnosticFramebuffer, - storage = checkNotNull(diagnosticStorage), - ) - diagnosticSetupNs += timing.setupNs - diagnosticDispatchNs += timing.dispatchNs - pendingDiagnosticBand = PendingRgbDiagnosticBand( - storage = diagnosticStorage, - outputCore = band.outputCore, - destinationHeight = timing.destinationHeight, - byteCount = timing.byteCount, - ) - } - } finally { - passWindow.endPass() - } - if (diagnosticSlotIndex >= 0) { - pendingDiagnosticBands[diagnosticSlotIndex] = - checkNotNull(pendingDiagnosticBand) - } - } - pendingDiagnosticBands.forEachIndexed { slot, pending -> - pending ?: return@forEachIndexed - passWindow.awaitResources( - label = "MGC RGB final diagnostic band ${pending.outputCore.top} host copy", - resources = longArrayOf( - GlesGpuScheduler.bufferResource(pending.storage.buffer), - ), - ) - copyRgbFixed16BandToHost( - capture = checkNotNull(diagnosticCapture), - pending = pending, - destination = checkNotNull(diagnosticHostBuffer), - ) - pendingDiagnosticBands[slot] = null - } - diagnosticStorages.forEach { storage -> - releasePixelPackBuffer(storage, "MGC Spatial RGB Fixed16 band slot") - } - diagnosticStoragesReleased = true - detachFramebufferColorAttachment(diagnosticFramebuffer) - passWindow.drain("MGC RGB fusion-to-chroma handoff") - releaseRgbFusionPhaseTextures( - retainedTexture = chromaPostprocessor.normalizationTargetTexture(), - label = "streamed-band", - ) - GlesGpuScheduler.memoryBarrier() - val chromaResult = chromaPostprocessor.process( - obtainOutputBuffer = { checkNotNull(cpuOutput) }, - deferFullSizeReadback = exportGpuLinearRgbSource, - onFinalSubmitted = if (exportGpuLinearRgbSource) { - { completionRecorder.mark(GpuStackCompletionStage.CHROMA_POSTPROCESS) } - } else { - null - }, - ) - postprocessedUi = chromaResult.exportedTextureId - if (exportGpuLinearRgbSource) { - check(postprocessedUi != 0) { - "MGC Spatial RGB chroma did not export its filtered texture" - } - gpuOutput = if (gpuLinearRgbStorage == GpuLinearRgbStorage.RGBA16UI) { - postprocessedUi.also { postprocessedUi = 0 } - } else { - GlesGpuCompletion.awaitSubmittedWork( - label = "MGC Spatial RGB IIR-to-float handoff", - checkGlError = ::checkGlError, - ) - createTexture( - outputWidth, - outputHeight, - GLES30.GL_RGBA16F, - GLES30.GL_NEAREST, - ).also { target -> - renderRgb16ToFloat(postprocessedUi, target) - GLES30.glDeleteTextures(1, intArrayOf(postprocessedUi), 0) - postprocessedUi = 0 - } - } - } - PLog.i( - TAG, - "MGC Spatial RGB streamed RAW uploads=$rawBandUploadCount " + - "bytes=$rawBandUploadBytes submit=" + - "${rawBandUploadNs / 1_000_000L}ms slots=${rawBandTextures.size} " + - "colorNoiseIir=${chromaResult.chromaSubmissionMs}ms " + - "chromaFinal=${chromaResult.finalSubmissionMs}ms", - ) - cpuOutput?.rewind() - val diagnosticFixed16 = diagnosticCapture?.let { - checkGlError("MGC Spatial RGB Fixed16 diagnostic pack") - PreparedTextureReadback( - byteCount = strengthFixed16ReadbackByteCount(it), - queuedGpuReadback = null, - cpuBuffer = checkNotNull(diagnosticHostBuffer), - mode = "${diagnosticStorages.size}-slot-band-pbo-host-rgb-planar-q14", - targetBindMs = diagnosticSetupNs / 1_000_000L, - readSubmitMs = diagnosticDispatchNs / 1_000_000L, - totalSubmitMs = - (diagnosticSetupNs + diagnosticDispatchNs) / 1_000_000L, - ) - } - val completionTimeline = if (gpuOutput != 0) { - completionRecorder.mark(GpuStackCompletionStage.FINAL_EXPORT) - completionRecorder.finish().also { timeline -> - if (timeline != null) { - passWindow.clearAfterCheckpoint() - } else { - passWindow.drain("MGC RGB final export without completion checkpoint") - } - } - } else { - passWindow.drain("MGC RGB CPU output completion") - null - } - if (gpuOutput != 0) { - if (textures.remove(gpuOutput)) { - textureSpecs.remove(gpuOutput) - } - } - return RgbMergeOutput( - cpuBuffer = cpuOutput, - gpuTexture = gpuOutput, - diagnosticFixed16 = diagnosticFixed16, - completionTimeline = completionTimeline, - ) - } catch (throwable: Throwable) { - completionRecorder.releasePending() - passWindow.drain("MGC RGB reconstruction failure") - if (!diagnosticStoragesReleased) { - diagnosticStorages.forEach { storage -> - releasePixelPackBuffer( - storage, - "failed MGC Spatial RGB Fixed16 band slot", - ) - } - } - if (postprocessedUi != 0) { - GLES30.glDeleteTextures(1, intArrayOf(postprocessedUi), 0) - } - if (gpuOutput != 0 && !textures.contains(gpuOutput)) { - GLES30.glDeleteTextures(1, intArrayOf(gpuOutput), 0) - } - LargeDirectBuffer.free(diagnosticHostBuffer) - LargeDirectBuffer.free(cpuOutput) - throw throwable - } - } - - /** - * Packs the isolated semantic merge accumulator before LSC and output-exposure scaling. - * Applying only cameraDomainScale produces the normalized camera-RGB domain expected by - * ComputeRgbNoiseModel; output noise coefficients are exposure-scaled once after the AOT. - */ - private fun packRgbFixed16TileReadback( - capture: StrengthCapture, - semanticAccumulator: Int, - opponentWeightAccumulator: Int, - outputCore: MgcSpatialRgbRect, - fixed16Texture: Int, - diagnosticFramebuffer: Int, - storage: PixelPackBuffer, - ): RgbDiagnosticPackTiming { - check(capture.outputMode == MgcSpatialOutputMode.RGB) - check( - packRgbFixed16FallbackProgram != 0 && - fixed16Texture != 0 && - diagnosticFramebuffer != 0 - ) - check(storage.buffer != 0) - val imageWidth = capture.geometry.imageWidth - val imageHeight = capture.geometry.imageHeight - val fixed16Width = capture.geometry.fixed16Width - val fixed16Height = capture.geometry.fixed16Height - require(outputCore.right <= imageWidth && outputCore.bottom <= imageHeight) - val destinationWidth = outputCore.width + - if (outputCore.right == imageWidth) fixed16Width - imageWidth else 0 - val destinationHeight = outputCore.height + - if (outputCore.bottom == imageHeight) fixed16Height - imageHeight else 0 - check(outputCore.left == 0 && destinationWidth == fixed16Width) { - "RGB Fixed16 band packing requires full-width horizontal bands" - } - val rowBytes = destinationWidth.toLong() * Short.SIZE_BYTES - val planeBytes = rowBytes * destinationHeight.toLong() - val packedByteCount = (planeBytes * 3L) - .also { bytes -> require(bytes in 1..storage.byteCount.toLong()) } - .toInt() - var setupNs = 0L - var submitNs = 0L - try { - for (channel in 0 until 3) { - val setupStartNs = System.nanoTime() - GLES30.glBindFramebuffer(GLES30.GL_FRAMEBUFFER, diagnosticFramebuffer) - GLES30.glViewport(0, 0, destinationWidth, destinationHeight) - GLES30.glDisable(GLES30.GL_BLEND) - GLES30.glUseProgram(packRgbFixed16FallbackProgram) - bindTexture( - packRgbFixed16FallbackProgram, - "uColorAndRWeight", - 0, - semanticAccumulator, - ) - bindTexture( - packRgbFixed16FallbackProgram, - "uGbWeights", - 1, - opponentWeightAccumulator, - ) - uniform1i(packRgbFixed16FallbackProgram, "uChannel", channel) - uniform2i( - packRgbFixed16FallbackProgram, - "uSourceSize", - outputCore.width, - outputCore.height, - ) - uniform3f( - packRgbFixed16FallbackProgram, - "uCameraDomainScale", - cameraDomainScale[0], - cameraDomainScale[1], - cameraDomainScale[2], - ) - setupNs += System.nanoTime() - setupStartNs - - val submitStartNs = System.nanoTime() - GLES30.glDrawArrays(GLES30.GL_TRIANGLES, 0, 3) - GLES30.glBindBuffer( - GLES30.GL_PIXEL_PACK_BUFFER, - storage.buffer, - ) - GLES30.glPixelStorei(GLES30.GL_PACK_ALIGNMENT, 1) - GLES30.glPixelStorei(GLES30.GL_PACK_ROW_LENGTH, destinationWidth) - val destinationOffset = channel.toLong() * planeBytes - val destinationEnd = - destinationOffset + - (destinationHeight - 1L) * rowBytes + - destinationWidth.toLong() * Short.SIZE_BYTES - check( - destinationOffset in 0..Int.MAX_VALUE.toLong() && - destinationEnd <= storage.byteCount.toLong() - ) - GLES30.glReadPixels( - 0, - 0, - destinationWidth, - destinationHeight, - GLES30.GL_RED_INTEGER, - GLES30.GL_SHORT, - destinationOffset.toInt(), - ) - GLES30.glBindBuffer(GLES30.GL_PIXEL_PACK_BUFFER, 0) - GLES30.glBindFramebuffer(GLES30.GL_FRAMEBUFFER, 0) - submitNs += System.nanoTime() - submitStartNs - } - } finally { - GLES30.glPixelStorei(GLES30.GL_PACK_ROW_LENGTH, 0) - GLES30.glBindBuffer(GLES30.GL_PIXEL_PACK_BUFFER, 0) - GLES30.glBindFramebuffer(GLES30.GL_FRAMEBUFFER, 0) - GLES30.glActiveTexture(GLES30.GL_TEXTURE1) - GLES30.glBindTexture(GLES30.GL_TEXTURE_2D, 0) - GLES30.glActiveTexture(GLES30.GL_TEXTURE0) - GLES30.glBindTexture(GLES30.GL_TEXTURE_2D, 0) - GLES30.glUseProgram(0) - } - checkGlError("MGC Spatial RGB Fixed16 fallback pack $outputCore") - return RgbDiagnosticPackTiming( - setupNs = setupNs, - dispatchNs = submitNs, - byteCount = packedByteCount, - destinationHeight = destinationHeight, - ) - } - - private fun copyRgbFixed16BandToHost( - capture: StrengthCapture, - pending: PendingRgbDiagnosticBand, - destination: ByteBuffer, - ) { - check(capture.outputMode == MgcSpatialOutputMode.RGB) - check(pending.outputCore.left == 0) - val fixed16Width = capture.geometry.fixed16Width - val fixed16Height = capture.geometry.fixed16Height - val rowBytes = fixed16Width * Short.SIZE_BYTES - val sourcePlaneBytes = rowBytes * pending.destinationHeight - val destinationPlaneBytes = rowBytes * fixed16Height - check(pending.byteCount == sourcePlaneBytes * 3) - check(destination.capacity() >= destinationPlaneBytes * 3) - val mapped = mapPixelPackBuffer( - pending.storage.buffer, - pending.byteCount, - "MGC Spatial RGB Fixed16 band top=${pending.outputCore.top}", - ) - try { - for (channel in 0 until 3) { - val sourceOffset = channel * sourcePlaneBytes - val destinationOffset = - channel * destinationPlaneBytes + pending.outputCore.top * rowBytes - val source = mapped.duplicate().apply { - position(sourceOffset) - limit(sourceOffset + sourcePlaneBytes) - } - destination.duplicate().apply { - position(destinationOffset) - put(source) - } - } - } finally { - unmapPixelPackBuffer(pending.storage.buffer) - } - } - private fun clearRgbAccumulators( semanticAccumulator: Int, opponentWeightAccumulator: Int, @@ -7467,320 +5803,180 @@ internal class GlesMgcRawSpatialStacker( GLES30.glBindFramebuffer(GLES30.GL_FRAMEBUFFER, 0) } - private fun renderRgbFrameContribution( - frame: RgbMergeFrame, - rawTexture: Int, - rawTextureOrigin: MgcSpatialRgbRect, - sourceRegion: MgcSpatialRgbRect, - outputCores: List, - chromaGuideRegionTexture: Int, - semanticAccumulator: Int, - opponentWeightAccumulator: Int, - accumulatorIsFullOutput: Boolean = false, - ) { - require(outputCores.isNotEmpty()) - GLES30.glUseProgram(mergeRgbProgram) - bindTexture(mergeRgbProgram, "uRaw", 0, rawTexture) - bindTexture(mergeRgbProgram, "uChromaGuideRegion", 1, chromaGuideRegionTexture) - bindTexture(mergeRgbProgram, "uAlignment", 2, frame.alignmentTexture) - bindTexture(mergeRgbProgram, "uFrameWeight", 3, frame.weightTexture) - bindTexture(mergeRgbProgram, "uCovariance", 4, frame.covarianceTexture) - uniform1f( - mergeRgbProgram, - "uGlobalFrameWeight", - frame.calibration.globalFrameWeight, - ) - uniform2i(mergeRgbProgram, "uRawSize", width, height) - uniform2i( - mergeRgbProgram, - "uRawTextureOrigin", - rawTextureOrigin.left, - rawTextureOrigin.top, - ) - uniform2i( - mergeRgbProgram, - "uRawRegionOrigin", - sourceRegion.left, - sourceRegion.top, - ) - uniform2i( - mergeRgbProgram, - "uRawRegionSize", - sourceRegion.width, - sourceRegion.height, - ) - uniform2i(mergeRgbProgram, "uOutputSize", outputWidth, outputHeight) - uniform4f( - mergeRgbProgram, - "uCovRangeRg", - COV_MIN_R, - COV_MAX_R - COV_MIN_R, - COV_MIN_G, - COV_MAX_G - COV_MIN_G, - ) - uniform2f( - mergeRgbProgram, - "uCovRangeB", - COV_MIN_B, - COV_MAX_B - COV_MIN_B, - ) - uniform4fv(mergeRgbProgram, "uGains", frame.calibration.gains) - uniform4fv( - mergeRgbProgram, - "uBlackLevelsTimesGains", - frame.calibration.blackTerms, - ) - uniform2f( - mergeRgbProgram, - "uGreenNoise", - 0.5f * (frame.calibration.shotNoise[1] + frame.calibration.shotNoise[2]), - 0.5f * (frame.calibration.readNoise[1] + frame.calibration.readNoise[2]), - ) - uniform1f( - mergeRgbProgram, - "uChromaEdgeNoiseSigmas", - RGB_CHROMA_EDGE_NOISE_SIGMAS, - ) - uniform1f( - mergeRgbProgram, - "uChromaEdgeSigmaFloor", - RGB_CHROMA_EDGE_SIGMA_FLOOR, - ) - uniform1f( - mergeRgbProgram, - "uInterpolationFlowTolerance", - SPATIAL_INTERPOLATION_FLOW_TOLERANCE, - ) - uniform1i(mergeRgbProgram, "uCfaPattern", cfaPattern) - uniform1i( - mergeRgbProgram, - "uUseFrameWeight", - if (frame.useFrameWeight) 1 else 0, - ) - GLES30.glEnable(GLES30.GL_BLEND) - try { - GLES30.glBlendEquation(GLES30.GL_FUNC_ADD) - GLES30.glBlendFunc(GLES30.GL_ONE, GLES30.GL_ONE) - bindRenderTargets( - intArrayOf(semanticAccumulator, opponentWeightAccumulator), - "MGC RGB contributions", - ) - outputCores.forEach { outputCore -> - val accumulatorLeft = if (accumulatorIsFullOutput) outputCore.left else 0 - val accumulatorTop = if (accumulatorIsFullOutput) outputCore.top else 0 - uniform2i( - mergeRgbProgram, - "uOutputOrigin", - outputCore.left, - outputCore.top, - ) - uniform2i( - mergeRgbProgram, - "uAccumulatorOrigin", - accumulatorLeft, - accumulatorTop, - ) - GLES30.glViewport( - accumulatorLeft, - accumulatorTop, - outputCore.width, - outputCore.height, - ) - GLES30.glDrawArrays(GLES30.GL_TRIANGLES, 0, 3) - } - GLES30.glBindFramebuffer(GLES30.GL_FRAMEBUFFER, 0) - checkGlError("MGC RGB contributions=${outputCores.size}") - } finally { - GLES30.glDisable(GLES30.GL_BLEND) - } - } - - private fun renderRgbChromaGuide( - frame: RgbMergeFrame, - rawTexture: Int, - rawTextureOrigin: MgcSpatialRgbRect, - sourceRegion: MgcSpatialRgbRect, - outputTexture: Int, - ) { - GLES30.glUseProgram(rgbChromaGuideProgram) - bindTexture(rgbChromaGuideProgram, "uRaw", 0, rawTexture) - uniform2i(rgbChromaGuideProgram, "uRawSize", width, height) - uniform2i( - rgbChromaGuideProgram, - "uRawTextureOrigin", - rawTextureOrigin.left, - rawTextureOrigin.top, - ) - uniform2i( - rgbChromaGuideProgram, - "uRegionOrigin", - sourceRegion.left, - sourceRegion.top, - ) - uniform2i( - rgbChromaGuideProgram, - "uRegionSize", - sourceRegion.width, - sourceRegion.height, - ) - uniform4fv(rgbChromaGuideProgram, "uGains", frame.calibration.gains) - uniform4fv( - rgbChromaGuideProgram, - "uBlackLevelsTimesGains", - frame.calibration.blackTerms, - ) - uniform1i(rgbChromaGuideProgram, "uCfaPattern", cfaPattern) - draw( - rgbChromaGuideProgram, - sourceRegion.width, - sourceRegion.height, - intArrayOf(outputTexture), - ) - } - - private fun renderRgbNormalizedTile( - semanticAccumulator: Int, - opponentWeightAccumulator: Int, - lensShadingTexture: Int, - outputCore: MgcSpatialRgbRect, - target: Int, - targetIsFullOutput: Boolean, - outputExposureScale: Float, - ) { - val targetLeft = if (targetIsFullOutput) outputCore.left else 0 - val targetTop = if (targetIsFullOutput) outputCore.top else 0 - bindRenderTargets(intArrayOf(target), "MGC RGB normalize tile ${outputCore.left},${outputCore.top}") - GLES30.glViewport(targetLeft, targetTop, outputCore.width, outputCore.height) - GLES30.glDisable(GLES30.GL_BLEND) - GLES30.glUseProgram(normalizeRgbProgram) - bindTexture(normalizeRgbProgram, "uColorAndRWeight", 0, semanticAccumulator) - bindTexture(normalizeRgbProgram, "uGbWeights", 1, opponentWeightAccumulator) - bindTexture(normalizeRgbProgram, "uLensShading", 2, lensShadingTexture) - uniform2i( - normalizeRgbProgram, - "uAccumulatorSize", - outputCore.width, - outputCore.height, - ) - uniform2i(normalizeRgbProgram, "uTargetOrigin", targetLeft, targetTop) - uniform2i( - normalizeRgbProgram, - "uOutputOrigin", - outputCore.left, - outputCore.top, - ) - uniform2i(normalizeRgbProgram, "uOutputSize", outputWidth, outputHeight) - uniform3f( - normalizeRgbProgram, - "uCameraDomainScale", - cameraDomainScale[0], - cameraDomainScale[1], - cameraDomainScale[2], - ) - uniform1f( - normalizeRgbProgram, - "uOutputExposureScale", - outputExposureScale, - ) - uniform1i(normalizeRgbProgram, "uUseLensShading", if (hasLensShading()) 1 else 0) - GLES30.glDrawArrays(GLES30.GL_TRIANGLES, 0, 3) - GLES30.glBindFramebuffer(GLES30.GL_FRAMEBUFFER, 0) - checkGlError("MGC Spatial RGB normalize tile $outputCore") - } - /** - * Streams native-grid planar F16 channels into RGBA16UI before lens shading and chroma denoise. + * Runs [GlesMgcSpatialRgbMergeShaders] over the burst and writes the normalized, lens-shaded + * RGB16 into [target]. Per frame: upload the RAW, compute its DemosaicGreenRaw16 guide in + * padded int16 planes, and accumulate it into four R32F sums; the alignment and acceptance + * slices are read directly from the strength atlases. */ - private fun uploadAndNormalizeOriginalAotRgb( - planarF16: ByteBuffer, + private fun mergeSpatialRgbFrames( + frames: List, + images: List, + mergeSharpness: Float, + capture: StrengthCapture, + referenceBlack: FloatArray, lensShadingTexture: Int, target: Int, outputExposureScale: Float, cameraWhite: FloatArray, ultrashortWeight: Int, ) { - check(normalizeAotRgbProgram != 0) - require(planarF16.isDirect) - require(outputExposureScale.isFinite() && outputExposureScale > 0f) - val planeByteCountLong = - rgbAotStorageWidth.toLong() * rgbAotStorageHeight * Short.SIZE_BYTES - require(planeByteCountLong in 1..Int.MAX_VALUE.toLong()) - val planeByteCount = planeByteCountLong.toInt() - require(planarF16.capacity().toLong() >= planeByteCountLong * 3L) - val planeTexture = createTexture( - rgbAotStorageWidth, - rgbAotStorageHeight, - GLES30.GL_R16F, - GLES30.GL_NEAREST, - ) + require(referenceBlack.size == 4) + // Offset of the red site; the AOT merges in a virtual RGGB frame anchored there. + val (redX, redY) = when (cfaPattern) { + 0 -> 0 to 0 // RGGB + 1 -> 1 to 0 // GRBG + 2 -> 0 to 1 // GBRG + 3 -> 1 to 1 // BGGR + else -> throw IllegalArgumentException("MGC Spatial RGB CFA pattern $cfaPattern") + } + val whiteBalance = calculationWhiteBalance + val overallGain = sabreResolveRawScale + val conversionGains = FloatArray(4) { whiteBalance[it] * overallGain } + val greenWhiteBalance = 0.5f * (whiteBalance[1] + whiteBalance[2]) + // DemosaicGreenRaw16 receives merge_sharpness as k = fcvtzs(clamp(s * 65536, 0, 65535)). + val greenImbalanceRetention = (mergeSharpness * 65536f).coerceIn(0f, 65535f).toInt() + val padding = GlesMgcGreenDemosaicShaders.PLANE_PADDING + val planeWidth = width + 2 * padding + val planeHeight = height + 2 * padding + val tileSize = GlesMgcSpatialRgbMergeShaders.TILE_SIZE + val raw = createTexture(width, height, GLES30.GL_R16UI, GLES30.GL_NEAREST) + val converted = createTexture(planeWidth, planeHeight, GLES30.GL_R16I, GLES30.GL_NEAREST) + val balanced = createTexture(planeWidth, planeHeight, GLES30.GL_R16I, GLES30.GL_NEAREST) + val green = createTexture(planeWidth, planeHeight, GLES30.GL_R16I, GLES30.GL_NEAREST) + // Red, green and blue sums and the weight sum; R32F is the read/write image format + // GLES 3.1 guarantees. + val sums = IntArray(4) { createTexture(width, height, GLES30.GL_R32F, GLES30.GL_NEAREST) } try { - GLES30.glBindBuffer(GLES30.GL_PIXEL_UNPACK_BUFFER, 0) - GLES30.glPixelStorei(GLES30.GL_UNPACK_ALIGNMENT, 1) - GLES30.glPixelStorei(GLES30.GL_UNPACK_ROW_LENGTH, 0) - for (channel in 0 until 3) { - val source = planarF16.duplicate().order(ByteOrder.nativeOrder()).apply { - position(channel * planeByteCount) - limit((channel + 1) * planeByteCount) + frames.forEachIndexed { index, frame -> + uploadRaw(images[frame.imageIndex], raw, "MGC Spatial RGB merge frame $index") + + var program = spatialRgbConvertProgram + GLES30.glUseProgram(program) + bindTexture(program, "uRaw", 0, raw) + uniform2i(program, "uRawSize", width, height) + uniform2i(program, "uRedSite", redX, redY) + uniform4fv(program, "uBlackLevels", referenceBlack) + uniform4fv(program, "uConversionGains", conversionGains) + draw(program, planeWidth, planeHeight, intArrayOf(converted)) + + program = spatialRgbGreenBalanceProgram + GLES30.glUseProgram(program) + bindTexture(program, "uConverted", 0, converted) + uniform2i(program, "uPlaneSize", planeWidth, planeHeight) + uniform1i(program, "uGreenImbalanceRetention", greenImbalanceRetention) + draw(program, planeWidth, planeHeight, intArrayOf(balanced)) + + program = spatialRgbGreenProgram + GLES30.glUseProgram(program) + bindTexture(program, "uBalanced", 0, balanced) + uniform2i(program, "uPlaneSize", planeWidth, planeHeight) + draw(program, planeWidth, planeHeight, intArrayOf(green)) + + val inputGain = frame.calibration.inputGain + program = spatialRgbAccumulateProgram + GLES31.glUseProgram(program) + bindTexture(program, "uRaw", 0, raw) + bindTexture(program, "uGreen", 1, green) + bindTexture(program, "uAlignmentAtlas", 2, capture.alignmentAtlas) + bindTexture(program, "uRejectionAtlas", 3, capture.rejectionAtlas) + uniform2i(program, "uRawSize", width, height) + uniform2i(program, "uRedSite", redX, redY) + uniform4fv(program, "uBlackLevels", referenceBlack) + uniform4fv(program, "uConversionGains", conversionGains) + uniform2i( + program, + "uAlignmentOriginX", + capture.alignmentLayout.originX(index), + capture.alignmentLayout.originY(index), + ) + uniform2i( + program, + "uAlignmentOriginY", + capture.alignmentLayout.originX(capture.frameCount + index), + capture.alignmentLayout.originY(capture.frameCount + index), + ) + uniform2i( + program, + "uRejectionOrigin", + capture.rejectionLayout.originX(index), + capture.rejectionLayout.originY(index), + ) + uniform2i(program, "uRejectionSize", capture.rejectionWidth, capture.rejectionHeight) + uniform3f( + program, + "uChannelScale", + inputGain / whiteBalance[0], + inputGain / greenWhiteBalance, + inputGain / whiteBalance[3], + ) + uniform1f(program, "uFrameWeight", capture.frameWeights[index]) + uniform1f(program, "uKernelSigma", capture.kernelSigmas[index]) + uniform1i(program, "uFirstFrame", if (index == 0) 1 else 0) + sums.forEachIndexed { unit, texture -> + GLES31.glBindImageTexture( + unit, + texture, + 0, + false, + 0, + GLES31.GL_READ_WRITE, + GLES30.GL_R32F, + ) } - GLES30.glBindTexture(GLES30.GL_TEXTURE_2D, planeTexture) - GLES30.glTexSubImage2D( - GLES30.GL_TEXTURE_2D, - 0, - 0, - 0, - rgbAotStorageWidth, - rgbAotStorageHeight, - GLES30.GL_RED, - GLES30.GL_HALF_FLOAT, - source, - ) - GLES30.glBindTexture(GLES30.GL_TEXTURE_2D, 0) - GLES30.glUseProgram(normalizeAotRgbProgram) - bindTexture(normalizeAotRgbProgram, "uChannelPlane", 0, planeTexture) - bindTexture(normalizeAotRgbProgram, "uLensShading", 1, lensShadingTexture) - // Bind a complete float texture even when the branch is disabled. - bindTexture(normalizeAotRgbProgram, "uUltrashortWeight", 2, - if (ultrashortWeight != 0) ultrashortWeight else lensShadingTexture) - uniform1i(normalizeAotRgbProgram, "uHasUltrashort", - if (ultrashortWeight != 0) 1 else 0) - GLES30.glUniform3fv(uniformLocation(normalizeAotRgbProgram, "uCameraWhite"), - 1, cameraWhite, 0) - uniform2i(normalizeAotRgbProgram, "uOutputSize", outputWidth, outputHeight) - uniform1f( - normalizeAotRgbProgram, - "uOutputExposureScale", - outputExposureScale, - ) - uniform1i( - normalizeAotRgbProgram, - "uUseLensShading", - if (hasLensShading()) 1 else 0, - ) - uniform1i(normalizeAotRgbProgram, "uChannel", channel) - GLES30.glColorMask( - channel == 0, - channel == 1, - channel == 2, - channel == 0, - ) - drawRegion( - program = normalizeAotRgbProgram, - target = target, - viewportLeft = 0, - viewportTop = 0, - viewportWidth = outputWidth, - viewportHeight = outputHeight, + GLES31.glDispatchCompute(ceilDiv(width, tileSize), ceilDiv(height, tileSize), 1) + // The next frame reads the sums back as images, the resolve as textures. + GLES31.glMemoryBarrier( + GLES31.GL_SHADER_IMAGE_ACCESS_BARRIER_BIT or + GLES31.GL_TEXTURE_FETCH_BARRIER_BIT, ) + sums.indices.forEach { unit -> + GLES31.glBindImageTexture( + unit, + 0, + 0, + false, + 0, + GLES31.GL_READ_WRITE, + GLES30.GL_R32F, + ) + } + checkGlError("MGC Spatial RGB merge frame $index") + GlesGpuScheduler.yieldToUiRenderer() } + + val program = spatialRgbResolveProgram + GLES30.glUseProgram(program) + bindTexture(program, "uSumRed", 0, sums[0]) + bindTexture(program, "uSumGreen", 1, sums[1]) + bindTexture(program, "uSumBlue", 2, sums[2]) + bindTexture(program, "uWeightSum", 3, sums[3]) + bindTexture(program, "uLensShading", 4, lensShadingTexture) + // Bind a complete float texture even when the branch is disabled. + bindTexture(program, "uUltrashortWeight", 5, + if (ultrashortWeight != 0) ultrashortWeight else lensShadingTexture) + uniform1i(program, "uHasUltrashort", if (ultrashortWeight != 0) 1 else 0) + uniform3f(program, "uCameraWhite", cameraWhite[0], cameraWhite[1], cameraWhite[2]) + uniform2i(program, "uOutputSize", outputWidth, outputHeight) + uniform1f(program, "uOutputExposureScale", outputExposureScale) + drawRegion( + program = program, + target = target, + viewportLeft = 0, + viewportTop = 0, + viewportWidth = outputWidth, + viewportHeight = outputHeight, + ) GLES31.glMemoryBarrier( GLES31.GL_FRAMEBUFFER_BARRIER_BIT or GLES31.GL_SHADER_IMAGE_ACCESS_BARRIER_BIT, ) - checkGlError("upload and normalize MGC V25 Spatial RGB AOT planes") + checkGlError("MGC Spatial RGB merge resolve") } finally { - GLES30.glColorMask(true, true, true, true) GLES30.glBindTexture(GLES30.GL_TEXTURE_2D, 0) - releaseOwnedTexture(planeTexture, "MGC V25 Spatial RGB AOT upload plane") + (intArrayOf(raw, converted, balanced, green) + sums).forEach { texture -> + releaseOwnedTexture(texture, "MGC Spatial RGB merge scratch") + } } } @@ -8095,74 +6291,6 @@ internal class GlesMgcRawSpatialStacker( checkGlError("upload $label") } - private fun uploadRawRegion( - image: SafeImage, - texture: Int, - region: MgcSpatialRgbRect, - label: String, - ) { - require(region.right <= width && region.bottom <= height) - val plane = image.planes.firstOrNull() - ?: throw IllegalArgumentException("$label has no RAW plane") - require(plane.pixelStride == RAW_BYTES_PER_PIXEL) { - "$label RAW pixel stride=${plane.pixelStride}, expected 2" - } - require(sourceBounds.right <= image.width && sourceBounds.bottom <= image.height) { - "$label RAW source=${image.width}x${image.height} crop=$sourceBounds" - } - require(plane.rowStride >= sourceBounds.right * RAW_BYTES_PER_PIXEL) { - "$label RAW row stride=${plane.rowStride} cannot address crop=$sourceBounds" - } - require(plane.rowStride % RAW_BYTES_PER_PIXEL == 0) { - "$label RAW row stride is not 16-bit aligned" - } - val buffer = plane.buffer.duplicate().order(ByteOrder.nativeOrder()) - val sourceOffset = buffer.position().toLong() + - (sourceBounds.top + region.top).toLong() * plane.rowStride + - (sourceBounds.left + region.left).toLong() * RAW_BYTES_PER_PIXEL - val sourceEnd = sourceOffset + - (region.height - 1L) * plane.rowStride + - region.width.toLong() * RAW_BYTES_PER_PIXEL - require(sourceOffset in 0..Int.MAX_VALUE.toLong() && sourceEnd <= buffer.limit()) { - "$label RAW region=$region exceeds plane buffer limit=${buffer.limit()}" - } - buffer.position(sourceOffset.toInt()) - GLES30.glBindBuffer(GLES30.GL_PIXEL_UNPACK_BUFFER, 0) - GLES30.glBindTexture(GLES30.GL_TEXTURE_2D, texture) - GLES30.glPixelStorei(GLES30.GL_UNPACK_ALIGNMENT, 1) - GLES30.glPixelStorei( - GLES30.GL_UNPACK_ROW_LENGTH, - plane.rowStride / RAW_BYTES_PER_PIXEL, - ) - GLES30.glTexSubImage2D( - GLES30.GL_TEXTURE_2D, - 0, - 0, - 0, - region.width, - region.height, - GLES30.GL_RED_INTEGER, - GLES30.GL_UNSIGNED_SHORT, - buffer, - ) - GLES30.glPixelStorei(GLES30.GL_UNPACK_ROW_LENGTH, 0) - GLES30.glBindTexture(GLES30.GL_TEXTURE_2D, 0) - checkGlError("upload $label region=$region") - } - - private fun expandRgbRawRegion( - region: MgcSpatialRgbRect, - radius: Int, - ): MgcSpatialRgbRect { - require(radius >= 0) - return MgcSpatialRgbRect( - left = max(0, region.left - radius), - top = max(0, region.top - radius), - right = minOf(width, region.right + radius), - bottom = minOf(height, region.bottom + radius), - ) - } - private fun createTexture( textureWidth: Int, textureHeight: Int, @@ -8502,51 +6630,6 @@ internal class GlesMgcRawSpatialStacker( ) } - /** Moves strength atlases out of GL storage before the full-resolution RGB output exists. */ - private fun materializeRgbStrengthAtlases( - capture: StrengthCapture, - ): Pair { - check(capture.outputMode == MgcSpatialOutputMode.RGB) - var alignmentHost: PreparedTextureReadback? = null - var rejectionHost: PreparedTextureReadback? = null - return try { - alignmentHost = materializePreparedReadbackToHost( - prepared = queuePreparedTextureReadback( - texture = capture.alignmentAtlas, - textureWidth = capture.alignmentLayout.atlasWidth, - textureHeight = capture.alignmentLayout.atlasHeight, - encoding = StrengthReadbackEncoding.FLOAT32, - byteCount = strengthAlignmentReadbackByteCount(capture), - label = "MGC Spatial RGB strength alignment atlas", - atlasLayout = capture.alignmentLayout, - ), - label = "MGC Spatial RGB strength alignment host", - ) - detachRenderTargets() - releaseOwnedTexture(capture.alignmentAtlas, "RGB strength alignment atlas") - - rejectionHost = materializePreparedReadbackToHost( - prepared = queuePreparedTextureReadback( - texture = capture.rejectionAtlas, - textureWidth = capture.rejectionLayout.atlasWidth, - textureHeight = capture.rejectionLayout.atlasHeight, - encoding = StrengthReadbackEncoding.UNORM8, - byteCount = strengthRejectionReadbackByteCount(capture), - label = "MGC Spatial RGB strength rejection atlas", - atlasLayout = capture.rejectionLayout, - ), - label = "MGC Spatial RGB strength rejection host", - ) - detachRenderTargets() - releaseOwnedTexture(capture.rejectionAtlas, "RGB strength rejection atlas") - checkNotNull(alignmentHost) to checkNotNull(rejectionHost) - } catch (throwable: Throwable) { - LargeDirectBuffer.free(alignmentHost?.cpuBuffer) - LargeDirectBuffer.free(rejectionHost?.cpuBuffer) - throw throwable - } - } - /** * Resolves the small persistent alignment grids once after temporal completion. Exact bounds * avoid replaying hundreds of unused RAW halo rows for every reconstruction band. @@ -8632,19 +6715,6 @@ internal class GlesMgcRawSpatialStacker( GLES30.glBindFramebuffer(GLES30.GL_FRAMEBUFFER, 0) } - private fun detachFramebufferColorAttachment(framebuffer: Int) { - if (framebuffer == 0) return - GLES30.glBindFramebuffer(GLES30.GL_FRAMEBUFFER, framebuffer) - GLES30.glFramebufferTexture2D( - GLES30.GL_FRAMEBUFFER, - GLES30.GL_COLOR_ATTACHMENT0, - GLES30.GL_TEXTURE_2D, - 0, - 0, - ) - GLES30.glBindFramebuffer(GLES30.GL_FRAMEBUFFER, 0) - } - private fun estimatedOwnedTextureBytes(): Long = textureSpecs.values.sumOf(::estimatedTextureBytes) @@ -9125,26 +7195,6 @@ internal class GlesMgcRawSpatialStacker( return level.gridHeight } - private fun rgbBandHeightCandidates(): IntArray = intArrayOf( - outputHeight, - 4096, - 3072, - 2048, - 1536, - MgcSpatialRgbTilePlanner.DEFAULT_OUTPUT_TILE_SIZE, - 768, - 512, - 384, - 256, - 192, - 128, - 64, - 32, - ).filter { it in 1..outputHeight } - .distinct() - .sortedDescending() - .toIntArray() - private companion object { fun gaussianKernel(size: Int, sigma: Float): FloatArray { require(size > 0) @@ -9176,15 +7226,7 @@ internal class GlesMgcRawSpatialStacker( const val SABRE_SIGNAL_ROW_STEP = 8 const val EGL_OPENGL_ES3_BIT_KHR = 0x00000040 const val RAW_BYTES_PER_PIXEL = 2 - const val RGB_AOT_TILE_SIZE = 16 - const val RGB_RAW_WINDOW_SLOTS = 2 - const val RGB_MAX_IN_FLIGHT_PASSES = 2 - const val RGB_DIAGNOSTIC_PBO_SLOTS = 2 const val RGB_TEXTURE_ADVISORY_BYTES = 640L * 1024L * 1024L - const val RGBA16_BYTES_PER_PIXEL = 8L - const val RGB_TEXTURE_ESTIMATE_RESERVE_BYTES = 8L * 1024L * 1024L - const val RGB_ONLINE_DRAW_BAND_HEIGHT = 1024 - const val RGB_CHROMA_GUIDE_RAW_RADIUS = 2 const val ALIGN_TARGET_FINEST_DIMENSION = 256 const val ALIGN_MIN_TILE_SIZE = 8 // Preferred Spatial options (38B0E48 / default tuning 528DA38) use 16 quads. @@ -9230,8 +7272,6 @@ internal class GlesMgcRawSpatialStacker( const val COV_MAX_G = 26.0516777f const val COV_MIN_B = -6.97557068f const val COV_MAX_B = 7.02652168f - const val RGB_CHROMA_EDGE_NOISE_SIGMAS = 2.5f - const val RGB_CHROMA_EDGE_SIGMA_FLOOR = 1f / 160f const val PIXEL_DIFFERENCE_SMOOTH_SIGMA = 500f const val PIXEL_DIFFERENCE_THRESHOLD = 150f const val REJECTION_FILTER_DOWNSAMPLE = 4 diff --git a/app/src/main/java/com/hinnka/mycamera/processor/GlesMgcSabreResolveShaders.kt b/app/src/main/java/com/hinnka/mycamera/processor/GlesMgcSabreResolveShaders.kt index a6bb247a..a64486bf 100644 --- a/app/src/main/java/com/hinnka/mycamera/processor/GlesMgcSabreResolveShaders.kt +++ b/app/src/main/java/com/hinnka/mycamera/processor/GlesMgcSabreResolveShaders.kt @@ -1,5 +1,10 @@ package com.hinnka.mycamera.processor +import com.hinnka.mycamera.processor.GlesMgcGreenDemosaicShaders.PLANE_PADDING +import com.hinnka.mycamera.processor.GlesMgcGreenDemosaicShaders.chromaOps +import com.hinnka.mycamera.processor.GlesMgcGreenDemosaicShaders.header +import com.hinnka.mycamera.processor.GlesMgcGreenDemosaicShaders.integerOps + /** * GLES implementation of MGC 9.6.080 V24 `gcam::ResolveSabreHalide` * (libgcastartup.so entry 0x34A55D4, worker 0x349B1B8). The algorithm notes live in @@ -12,6 +17,9 @@ package com.hinnka.mycamera.processor * 1. `converted_to_int`: remosaic the dehomogenized RGBA16F colour into an int16 CFA. * 2. `g_gb`: Gr/Gb balance at G sites; R/B sites keep their converted value. * 3. `g_b$1`: adaptive green at R/B sites; G sites keep their balanced value. + * + * Passes 2 and 3 are the green reconstruction this AOT shares with V25's + * `gcam::DemosaicGreenRaw16Halide`; they live in [GlesMgcGreenDemosaicShaders]. * 4. `demosaic` + `output`: chroma interpolation, coverage blend, final gains and lens shading, * written as the normalized RGBA16UI camera RGB the chroma stage consumes. * @@ -22,92 +30,6 @@ package com.hinnka.mycamera.processor * SSHL by a signed byte. The float stages around it run in native binary32. */ internal object GlesMgcSabreResolveShaders { - const val PLANE_PADDING = 4 - - private val header = """ - #version 310 es - precision highp float; - precision highp int; - precision highp sampler2D; - precision highp isampler2D; - """.trimIndent() - - private val integerOps = """ - const int PLANE_PADDING = $PLANE_PADDING; - - int s16(int v) { return (v << 16) >> 16; } - int u16(int v) { return v & 0xffff; } - int clz16(int x) { return x == 0 ? 16 : 15 - findMSB(x); } - int clz32(uint x) { return x == 0u ? 32 : 31 - findMSB(x); } - - // SSHL .8h: the shift is the signed low byte of the lane; negative shifts are arithmetic. - int sshl16(int x, int lane) { - int s = ((lane & 0xff) << 24) >> 24; - if (s >= 0) return s >= 16 ? 0 : s16(x << s); - if (s <= -16) return x < 0 ? -1 : 0; - return x >> (-s); - } - int shadd(int a, int b) { return (a + b) >> 1; } - int srhadd(int a, int b) { return (a + b + 1) >> 1; } - int sabd(int a, int b) { return abs(a - b); } - int urhadd(int a, int b) { return (a + b + 1) >> 1; } - int sqadd(int a, int b) { return clamp(a + b, -32768, 32767); } - int sqsub(int a, int b) { return clamp(a - b, -32768, 32767); } - - // Inverse-gradient pair blend. Candidate A has error dA, candidate B has error dB. - struct Ig1 { - bool aIsNear; - int shift; - }; - Ig1 makeIg1(int dA, int dB) { - int hA = dA >> 1; - int hB = dB >> 1; - int total = max(u16(hA + hB), 1); - return Ig1(hB > hA, clz16(total) - clz16(min(hA, hB))); - } - int blend1(Ig1 g, int xA, int xB) { - int nearValue = g.aIsNear ? xA : xB; - int farValue = g.aIsNear ? xB : xA; - return s16(nearValue + sshl16(s16(farValue - nearValue), g.shift)); - } - - // Inverse-squared-cost blend; X has cost cX and Y has cost cY. - int ig2(int cX, int cY, int x, int y) { - uint sX = (uint(cX) * uint(cX)) >> 1; - uint sY = (uint(cY) * uint(cY)) >> 1; - bool xIsNear = sY > sX; - int nearValue = xIsNear ? x : y; - int farValue = xIsNear ? y : x; - uint total = max(sX + sY, 1u); - int shift = clamp(s16(clz32(total) - clz32(min(sX, sY))), -15, 15); - return s16(nearValue + sshl16(s16(farValue - nearValue), shift)); - } - - // Bit below the leading one: the half-step fraction of log2(x). - int log2Fraction(int x) { return sshl16(x, clz16(u16(x)) - 14) & 1; } - - // Log-domain ratio correction: xWeighted * g / gWeighted in half-step powers of two. - int ratioCorrect(int xWeighted, int g, int gWeighted) { - int xp = max(xWeighted, 0); - int m = max(xp, max(gWeighted, g)); - int l = s16( - log2Fraction(xp) - 2 * clz16(u16(xp)) + 2 * clz16(u16(m)) - log2Fraction(m) - ); - int t = sshl16(sqsub(g, gWeighted), max(s16(l >> 1), -15)); - int odd = (l & 1) != 0 ? t >> 1 : 0; - return sqadd(xWeighted, s16(odd + t)); - } - - int planeAt(isampler2D plane, ivec2 planeSize, int u, int v) { - ivec2 p = clamp( - ivec2(u + PLANE_PADDING, v + PLANE_PADDING), - ivec2(0), - planeSize - ivec2(1) - ); - return texelFetch(plane, p, 0).r; - } - """.trimIndent() - /** Pass 1, `converted_to_int`: int16(clamp(roundEven(c * S), -32768, 32767)). */ val convertToInt = """ ${header.prependIndent(" ").trimStart()} @@ -128,122 +50,6 @@ internal object GlesMgcSabreResolveShaders { } """.trimIndent() - /** - * Pass 2, `g_gb`: blur = (4G + diagonal G + 4) >> 3 and - * G' = blur + (((G - blur) * k + 0x8000) >> 16), where k = 0 equalizes Gr/Gb fully. - */ - val greenBalance = """ - ${header.prependIndent(" ").trimStart()} - uniform highp isampler2D uConverted; - uniform ivec2 uPlaneSize; - uniform int uGreenImbalanceRetention; - layout(location = 0) out highp ivec4 oBalanced; - - ${integerOps.prependIndent(" ").trimStart()} - - int converted(int u, int v) { return planeAt(uConverted, uPlaneSize, u, v); } - - void main() { - ivec2 virtualSite = ivec2(gl_FragCoord.xy) - ivec2(PLANE_PADDING); - int u = virtualSite.x; - int v = virtualSite.y; - int g = converted(u, v); - if (((u + v) & 1) == 0) { - oBalanced = ivec4(g, 0, 0, 0); - return; - } - int total = 4 * g + converted(u - 1, v - 1) + converted(u + 1, v - 1) + - converted(u - 1, v + 1) + converted(u + 1, v + 1); - int blur = s16((total + 4) >> 3); - int difference = s16(g - blur); - int correction = s16( - int(uint(difference * uGreenImbalanceRetention) + 0x8000u) >> 16 - ); - oBalanced = ivec4(s16(correction + blur), 0, 0, 0); - } - """.trimIndent() - - /** - * Pass 3, `g_b$1`: green at R/B sites from directional (G + C) / 2 estimates, inverse-gradient - * candidate blends, log-domain ratio correction and inverse-squared direction costs. - */ - val greenAtColor = """ - ${header.prependIndent(" ").trimStart()} - uniform highp isampler2D uBalanced; - uniform ivec2 uPlaneSize; - layout(location = 0) out highp ivec4 oGreen; - - ${integerOps.prependIndent(" ").trimStart()} - - // R/B sites hold the converted value, G sites the balanced green. - int at(int u, int v) { return planeAt(uBalanced, uPlaneSize, u, v); } - - void main() { - ivec2 virtualSite = ivec2(gl_FragCoord.xy) - ivec2(PLANE_PADDING); - int u = virtualSite.x; - int v = virtualSite.y; - int c = at(u, v); - if (((u + v) & 1) != 0) { - oGreen = ivec4(c, 0, 0, 0); - return; - } - int cL = at(u - 2, v); - int cR = at(u + 2, v); - int cU = at(u, v - 2); - int cD = at(u, v + 2); - int gl = at(u - 1, v); - int gr = at(u + 1, v); - int gu = at(u, v - 1); - int gd = at(u, v + 1); - int ul = at(u - 1, v - 1); - int ur = at(u + 1, v - 1); - int dl = at(u - 1, v + 1); - int dr = at(u + 1, v + 1); - - int eH = srhadd(shadd(gl, gr), c); - int eR = srhadd(shadd(c, cR), gr); - int eL = srhadd(shadd(cL, c), gl); - int eV = srhadd(shadd(gu, gd), c); - int eD = srhadd(shadd(c, cD), gd); - int eU = srhadd(shadd(cU, c), gu); - - Ig1 horizontal = makeIg1(sabd(eH, eR), sabd(eH, eL)); - int eHWeighted = blend1(horizontal, eR, eL); - int gH = blend1(horizontal, gr, gl); - Ig1 vertical = makeIg1(sabd(eV, eD), sabd(eV, eU)); - int eVWeighted = blend1(vertical, eD, eU); - int gV = blend1(vertical, gd, gu); - - int cH = shadd(srhadd(gl, gr), c); - int cV = shadd(srhadd(gu, gd), c); - int eHUpDown = srhadd( - shadd(srhadd(at(u - 1, v - 2), at(u + 1, v - 2)), cU), - shadd(srhadd(at(u - 1, v + 2), at(u + 1, v + 2)), cD) - ); - int eVLeftRight = srhadd( - shadd(srhadd(at(u - 2, v - 1), at(u - 2, v + 1)), cL), - shadd(srhadd(at(u + 2, v - 1), at(u + 2, v + 1)), cR) - ); - int pl = shadd(srhadd(ul, dl), gl); - int pr = shadd(srhadd(ur, dr), gr); - int pu = shadd(srhadd(ul, ur), gu); - int pd = shadd(srhadd(dl, dr), gd); - // (|.| >> 2) * 9 is a wrapping 16-bit MUL then USHR #3; the sums are USRA mod 2^16. - int costA = u16( - (u16((sabd(cV, eVLeftRight) >> 2) * 9) >> 3) + - (sabd(cV, srhadd(pl, pr)) >> 3) + (sabd(pl, pr) >> 1) - ); - int costB = u16( - (u16((sabd(cH, eHUpDown) >> 2) * 9) >> 3) + - (sabd(cH, srhadd(pu, pd)) >> 3) + (sabd(pu, pd) >> 1) - ); - - int greenH = ratioCorrect(gH, eH, eHWeighted); - int greenV = ratioCorrect(gV, eV, eVWeighted); - oGreen = ivec4(ig2(costB, costA, greenV, greenH), 0, 0, 0); - } - """.trimIndent() - /** * Pass 4, `demosaic` + `output`. The coverage weight blends the accumulated colour toward the * demosaic; the result times the final gains and the lens shading is the black-free camera RGB, @@ -271,45 +77,7 @@ internal object GlesMgcSabreResolveShaders { int converted(int u, int v) { return planeAt(uBalanced, uPlaneSize, u, v); } int green(int u, int v) { return planeAt(uGreen, uPlaneSize, u, v); } - // Chroma of colour `wantBlue ? B : R` at a site whose native colour differs. - int chroma(int u, int v, bool wantBlue) { - int nativeOffset = wantBlue ? 1 : 0; - bool sameRow = ((v - nativeOffset) & 1) == 0; - bool sameColumn = ((u - nativeOffset) & 1) == 0; - int gc = green(u, v); - if (sameRow && !sameColumn) { - Ig1 g = makeIg1(sabd(gc, green(u + 1, v)), sabd(gc, green(u - 1, v))); - int xWeighted = blend1(g, converted(u + 1, v), converted(u - 1, v)); - int gWeighted = blend1(g, green(u + 1, v), green(u - 1, v)); - return ratioCorrect(xWeighted, gc, gWeighted); - } - if (!sameRow && sameColumn) { - Ig1 g = makeIg1(sabd(gc, green(u, v + 1)), sabd(gc, green(u, v - 1))); - int xWeighted = blend1(g, converted(u, v + 1), converted(u, v - 1)); - int gWeighted = blend1(g, green(u, v + 1), green(u, v - 1)); - return ratioCorrect(xWeighted, gc, gWeighted); - } - int center = converted(u, v); - int topLeft = converted(u - 1, v - 1); - int topRight = converted(u + 1, v - 1); - int bottomLeft = converted(u - 1, v + 1); - int bottomRight = converted(u + 1, v + 1); - Ig1 g1 = makeIg1(sabd(gc, green(u + 1, v - 1)), sabd(gc, green(u - 1, v + 1))); - int x1 = ratioCorrect( - blend1(g1, topRight, bottomLeft), - gc, - blend1(g1, green(u + 1, v - 1), green(u - 1, v + 1)) - ); - Ig1 g2 = makeIg1(sabd(gc, green(u + 1, v + 1)), sabd(gc, green(u - 1, v - 1))); - int x2 = ratioCorrect( - blend1(g2, bottomRight, topLeft), - gc, - blend1(g2, green(u + 1, v + 1), green(u - 1, v - 1)) - ); - int cost2 = urhadd(sabd(center, topLeft), sabd(center, bottomRight)); - int cost1 = urhadd(sabd(center, bottomLeft), sabd(center, topRight)); - return ig2(cost2, cost1, x2, x1); - } + ${chromaOps.prependIndent(" ").trimStart()} void main() { ivec2 site = ivec2(gl_FragCoord.xy); diff --git a/app/src/main/java/com/hinnka/mycamera/processor/GlesMgcSpatialRgbMergeShaders.kt b/app/src/main/java/com/hinnka/mycamera/processor/GlesMgcSpatialRgbMergeShaders.kt new file mode 100644 index 00000000..90e9a443 --- /dev/null +++ b/app/src/main/java/com/hinnka/mycamera/processor/GlesMgcSpatialRgbMergeShaders.kt @@ -0,0 +1,243 @@ +package com.hinnka.mycamera.processor + +import com.hinnka.mycamera.processor.GlesMgcGreenDemosaicShaders.PLANE_PADDING +import com.hinnka.mycamera.processor.GlesMgcGreenDemosaicShaders.chromaOps +import com.hinnka.mycamera.processor.GlesMgcGreenDemosaicShaders.integerOps +import com.hinnka.mycamera.processor.GlesMgcGreenDemosaicShaders.raw16Ops + +/** + * GLES implementation of MGC 9.7.047 V25 `gcam::MergeRgbRaw16F16TileSize16Halide` + * (libgcastartup.so wrapper 0x371990C, worker 0x370F514). The algorithm notes live in + * tools/mgc_demosaic_green/MERGE.md. + * + * Everything runs in the virtual RGGB frame whose (0, 0) is the sensor's red site. Per burst frame + * f and 16x16 output tile T with alignment a (Bayer quads), the AOT + * + * 1. gathers the frame at the quad-aligned offset d = 2 * roundEven(a) (UnpackAlignedRaw), with the + * RAW mirrored per colour plane and the DemosaicGreenRaw16 output mirrored per pixel; + * 2. demosaics it with the integer chroma interpolation it shares with ResolveSabre, on the + * same `wb_gains_applied` int16(roundEven(wb[c] * overallGain * (raw - black[c]))) as + * DemosaicGreenRaw16, and divides by the white balance; + * 3. resamples it by the sub-quad remainder r = 2a - d with a 3x3 Gaussian + * w(i, j) = exp(-0.5 * ((i - r.x)^2 + (j - r.y)^2) * sigma_f^2); + * 4. weights it by frameWeight_f times the RAW/4 acceptance, bilinearly upsampled with half-pixel + * centres, and accumulates sum(R * inputGain_f * resampled) and sum(R * sum(w)). + * + * [resolve] divides the sums and applies the output normalization. Everything outside the + * integer demosaic runs in native binary32. + */ +internal object GlesMgcSpatialRgbMergeShaders { + const val TILE_SIZE = 16 + // TILE_SIZE plus the one-pixel ring the 3x3 resampling reads. + private const val TILE_SPAN = 18 + + /** + * One burst frame into the four R32F accumulators. A work group owns one output tile: its 64 + * invocations demosaic the tile's aligned 18x18 neighbourhood into shared memory, then each + * accumulates a 2x2 block of output pixels. + */ + val accumulateFrame = """ + #version 310 es + layout(local_size_x = 8, local_size_y = 8) in; + precision highp float; + precision highp int; + precision highp sampler2D; + precision highp isampler2D; + precision highp usampler2D; + precision highp image2D; + uniform highp usampler2D uRaw; + uniform ivec2 uRawSize; + uniform ivec2 uRedSite; + uniform vec4 uBlackLevels; + // whiteBalanceGains[c] * overallGain. + uniform vec4 uConversionGains; + // DemosaicGreenRaw16 output of this frame, padded by PLANE_PADDING. + uniform highp isampler2D uGreen; + uniform highp sampler2D uAlignmentAtlas; + uniform ivec2 uAlignmentOriginX; + uniform ivec2 uAlignmentOriginY; + uniform highp sampler2D uRejectionAtlas; + uniform ivec2 uRejectionOrigin; + uniform ivec2 uRejectionSize; + // inputGain / white balance of R, G, B. + uniform vec3 uChannelScale; + uniform float uFrameWeight; + uniform float uKernelSigma; + uniform int uFirstFrame; + layout(r32f, binding = 0) uniform highp image2D uSumRed; + layout(r32f, binding = 1) uniform highp image2D uSumGreen; + layout(r32f, binding = 2) uniform highp image2D uSumBlue; + layout(r32f, binding = 3) uniform highp image2D uWeightSum; + + const int TILE_SIZE = $TILE_SIZE; + const int TILE_SPAN = $TILE_SPAN; + shared int sRed[$TILE_SPAN * $TILE_SPAN]; + shared int sGreen[$TILE_SPAN * $TILE_SPAN]; + shared int sBlue[$TILE_SPAN * $TILE_SPAN]; + + ${integerOps.prependIndent(" ").trimStart()} + + ${raw16Ops.prependIndent(" ").trimStart()} + + int converted(int u, int v) { return convertedSample(ivec2(u, v)); } + + // The gathered DemosaicGreenRaw16 output mirrors per pixel (index -1 reads 0). + int green(int u, int v) { + ivec2 p = ivec2(mirrorIndex(u, uRawSize.x), mirrorIndex(v, uRawSize.y)); + return texelFetch(uGreen, p + ivec2(PLANE_PADDING), 0).r; + } + + ${chromaOps.prependIndent(" ").trimStart()} + + // Quad-aligned shift d = 2 * roundEven(a) of the tile's alignment, and the remainder 2a - d. + void tileShift(ivec2 tile, out ivec2 shift, out vec2 remainder) { + vec2 alignment = vec2( + texelFetch(uAlignmentAtlas, uAlignmentOriginX + tile, 0).r, + texelFetch(uAlignmentAtlas, uAlignmentOriginY + tile, 0).r + ); + shift = 2 * ivec2(roundEven(alignment)); + remainder = 2.0 * alignment - vec2(shift); + } + + // Bilinear 4x upsampling with half-pixel centres: pixel 4j + k lies at RAW/4 coordinate + // j + (2k - 3) / 8, so its second source cell carries (2k + 5) & 7 eighths. + int acceptanceCell(int p) { return (p >> 2) - 1 + ((p & 3) >= 2 ? 1 : 0); } + float acceptanceFraction(int p) { return float((2 * (p & 3) + 5) & 7) * 0.125; } + + float acceptanceAt(int x, int y) { + ivec2 cell = clamp(ivec2(x, y), ivec2(0), uRejectionSize - ivec2(1)); + return texelFetch(uRejectionAtlas, uRejectionOrigin + cell, 0).r; + } + + // frameWeight times the upsampled acceptance. + float acceptance(ivec2 p) { + int x0 = acceptanceCell(p.x); + int y0 = acceptanceCell(p.y); + float fx = acceptanceFraction(p.x); + float top = mix(acceptanceAt(x0, y0), acceptanceAt(x0 + 1, y0), fx); + float bottom = mix(acceptanceAt(x0, y0 + 1), acceptanceAt(x0 + 1, y0 + 1), fx); + return uFrameWeight * mix(top, bottom, acceptanceFraction(p.y)); + } + + void loadTile(ivec2 origin) { + int lane = int(gl_LocalInvocationIndex); + for (int index = lane; index < TILE_SPAN * TILE_SPAN; index += 64) { + int u = origin.x + index % TILE_SPAN; + int v = origin.y + index / TILE_SPAN; + int cfaColor = (u & 1) + (v & 1); + sRed[index] = cfaColor == 0 ? converted(u, v) : chroma(u, v, false); + sGreen[index] = green(u, v); + sBlue[index] = cfaColor == 2 ? converted(u, v) : chroma(u, v, true); + } + } + + void accumulateTile(ivec2 tile, vec2 remainder) { + float sigmaSquared = uKernelSigma * uKernelSigma; + float weights[9]; + float weightTotal = 0.0; + for (int j = 0; j < 3; ++j) { + for (int i = 0; i < 3; ++i) { + vec2 d = vec2(i - 1, j - 1) - remainder; + float w = exp(-0.5 * dot(d, d) * sigmaSquared); + weights[j * 3 + i] = w; + weightTotal += w; + } + } + for (int by = 0; by < 2; ++by) { + for (int bx = 0; bx < 2; ++bx) { + ivec2 local = 2 * ivec2(gl_LocalInvocationID.xy) + ivec2(bx, by); + ivec2 p = tile * TILE_SIZE + local; + if (p.x >= uRawSize.x || p.y >= uRawSize.y) continue; + vec3 resampled = vec3(0.0); + for (int j = 0; j < 3; ++j) { + for (int i = 0; i < 3; ++i) { + int index = (local.y + j) * TILE_SPAN + local.x + i; + resampled += weights[j * 3 + i] * + vec3(sRed[index], sGreen[index], sBlue[index]); + } + } + float accepted = acceptance(p); + vec3 color = accepted * uChannelScale * resampled; + float weightSum = accepted * weightTotal; + if (uFirstFrame == 0) { + color += vec3( + imageLoad(uSumRed, p).r, + imageLoad(uSumGreen, p).r, + imageLoad(uSumBlue, p).r + ); + weightSum += imageLoad(uWeightSum, p).r; + } + imageStore(uSumRed, p, vec4(color.r, 0.0, 0.0, 0.0)); + imageStore(uSumGreen, p, vec4(color.g, 0.0, 0.0, 0.0)); + imageStore(uSumBlue, p, vec4(color.b, 0.0, 0.0, 0.0)); + imageStore(uWeightSum, p, vec4(weightSum, 0.0, 0.0, 0.0)); + } + } + } + + void main() { + ivec2 tile = ivec2(gl_WorkGroupID.xy); + ivec2 shift; + vec2 remainder; + tileShift(tile, shift, remainder); + loadTile(tile * TILE_SIZE + shift - ivec2(1)); + barrier(); + accumulateTile(tile, remainder); + } + """.trimIndent() + /** + * The merged ratio sum / weight (Q14 scale) followed by the output normalization: exposure + * scale, CameraWhite bound, lens shading and RGB16 encoding. + */ + val resolve = """ + #version 310 es + precision highp float; + precision highp int; + precision highp sampler2D; + uniform highp sampler2D uSumRed; + uniform highp sampler2D uSumGreen; + uniform highp sampler2D uSumBlue; + uniform highp sampler2D uWeightSum; + // RGGB gains of the lens shading map; a 1x1 map of ones when the capture has none. + uniform highp sampler2D uLensShading; + uniform sampler2D uUltrashortWeight; + uniform vec3 uCameraWhite; + uniform int uHasUltrashort; + uniform ivec2 uOutputSize; + uniform float uOutputExposureScale; + layout(location = 0) out highp uvec4 oRgb16; + + void main() { + ivec2 p = ivec2(gl_FragCoord.xy); + vec2 uv = (vec2(p) + vec2(0.5)) / vec2(uOutputSize); + vec3 sums = vec3( + texelFetch(uSumRed, p, 0).r, + texelFetch(uSumGreen, p, 0).r, + texelFetch(uSumBlue, p, 0).r + ); + vec3 merged = sums / (texelFetch(uWeightSum, p, 0).r * 16384.0); + vec4 map = texture(uLensShading, uv); + vec3 shading = vec3(map.r, 0.5 * (map.g + map.b), map.a); + // Sensor saturation precedes lens-shading correction, so CameraWhite bounds the + // unshaded sensor-domain value and the shading gain applies to the clipped result. + // Clipping after shading would cap unsaturated off-axis samples at the reference + // white, outside the (unshaded) highlight mask the ultrashort replaces. + // CameraWhite must follow the exposures that actually supply this pixel. + // A rejected short leaves the reference's saturated RGB at 1/ratio in the + // exported short domain; clipping it later against short-domain CameraWhite + // misses the reference plateau and preserves its false magenta chroma. + // The selected short slice has weight m and unit frame weight, while the + // reference slice alone keeps (1 - m); the short's share of the merge is thus + // at most m, and the merged white is bounded by mix(referenceWhite, shortWhite, m). + // The bound must stay continuous in m: switching on m > 0 steps the cap along + // the RAW/4 weight texel grid and draws a staircase through the highlight. + float shortShare = uHasUltrashort != 0 + ? clamp(texture(uUltrashortWeight, uv).r, 0.0, 1.0) + : 0.0; + float whiteScale = mix(uOutputExposureScale, 1.0, shortShare); + vec3 outputValue = + min(merged * uOutputExposureScale, uCameraWhite * whiteScale) * shading; + oRgb16 = uvec4(uvec3(round(clamp(outputValue, 0.0, 1.0) * 65535.0)), 0u); + } + """.trimIndent() +} diff --git a/app/src/main/java/com/hinnka/mycamera/processor/MgcSpatialDiagnosticGeometry.kt b/app/src/main/java/com/hinnka/mycamera/processor/MgcSpatialDiagnosticGeometry.kt index 38cd784b..7eaf5f1c 100644 --- a/app/src/main/java/com/hinnka/mycamera/processor/MgcSpatialDiagnosticGeometry.kt +++ b/app/src/main/java/com/hinnka/mycamera/processor/MgcSpatialDiagnosticGeometry.kt @@ -7,9 +7,6 @@ internal data class MgcSpatialDiagnosticGeometry( val alignmentHeight: Int, val rejectionWidth: Int, val rejectionHeight: Int, - val fixed16Width: Int, - val fixed16Height: Int, - val fixed16SampleCount: Long, ) /** Exact host geometry required by the lifted Bayer/RGB Spatial noise-model AOT kernels. */ @@ -21,17 +18,6 @@ internal fun mgcSpatialDiagnosticGeometry( require(imageWidth >= 4 && imageHeight >= 4) val isBayer = outputMode == MgcSpatialOutputMode.BAYER val alignmentTileSize = if (isBayer) 8 else 16 - val fixed16Width = if (isBayer) { - ceilDiv(imageWidth, 16) * 8 - } else { - ceilDiv(imageWidth, 16) * 16 - } - val fixed16Height = if (isBayer) { - ceilDiv(imageHeight, 16) * 8 - } else { - ceilDiv(imageHeight, 16) * 16 - } - val fixed16Channels = if (isBayer) 4L else 3L return MgcSpatialDiagnosticGeometry( imageWidth = imageWidth, imageHeight = imageHeight, @@ -42,9 +28,6 @@ internal fun mgcSpatialDiagnosticGeometry( // acceptance domain up makes the RGB atlas read past every source slice. rejectionWidth = imageWidth / 4, rejectionHeight = imageHeight / 4, - fixed16Width = fixed16Width, - fixed16Height = fixed16Height, - fixed16SampleCount = fixed16Width.toLong() * fixed16Height * fixed16Channels, ) } diff --git a/app/src/main/java/com/hinnka/mycamera/processor/MgcSpatialRgbMerger.kt b/app/src/main/java/com/hinnka/mycamera/processor/MgcSpatialRgbMerger.kt deleted file mode 100644 index 0791a052..00000000 --- a/app/src/main/java/com/hinnka/mycamera/processor/MgcSpatialRgbMerger.kt +++ /dev/null @@ -1,102 +0,0 @@ -package com.hinnka.mycamera.processor - -import java.nio.ByteBuffer - -/** - * JNI boundary for MGC 9.7.047 V25's original Spatial RGB merge AOT. - * - * `outputWidth`/`outputHeight` are the logical AOT image geometry used by the merge equations; - * `outputStorageWidth`/`outputStorageHeight` describe only the 16x16-aligned Halide allocation. - */ -internal object MgcSpatialRgbMerger { - init { - System.loadLibrary("my-native-lib") - } - - fun merge( - rawBuffers: Array, - rawOffsets: IntArray, - rawRowStrides: IntArray, - alignment: ByteBuffer, - alignmentWidth: Int, - alignmentHeight: Int, - rejection: ByteBuffer, - rejectionWidth: Int, - rejectionHeight: Int, - frameWeights: FloatArray, - whiteBalanceGains: FloatArray, - inputBlackLevelsRgb: FloatArray, - inputBlackLevelsRggb: FloatArray, - inputGains: FloatArray, - overallGain: Float, - mergeSharpness: Float, - kernelSigmas: FloatArray, - rawWidth: Int, - rawHeight: Int, - outputWidth: Int, - outputHeight: Int, - outputStorageWidth: Int, - outputStorageHeight: Int, - cfaPattern: Int, - outputPlanarF16: ByteBuffer, - ) { - val result = nativeMerge( - rawBuffers, - rawOffsets, - rawRowStrides, - alignment, - alignmentWidth, - alignmentHeight, - rejection, - rejectionWidth, - rejectionHeight, - frameWeights, - whiteBalanceGains, - inputBlackLevelsRgb, - inputBlackLevelsRggb, - inputGains, - overallGain, - mergeSharpness, - kernelSigmas, - rawWidth, - rawHeight, - outputWidth, - outputHeight, - outputStorageWidth, - outputStorageHeight, - cfaPattern, - outputPlanarF16, - ) - check(result == 0) { "MGC MergeRgbRaw16F16 failed with status=$result" } - outputPlanarF16.position(0) - outputPlanarF16.limit(outputPlanarF16.capacity()) - } - - private external fun nativeMerge( - rawBuffers: Array, - rawOffsets: IntArray, - rawRowStrides: IntArray, - alignment: ByteBuffer, - alignmentWidth: Int, - alignmentHeight: Int, - rejection: ByteBuffer, - rejectionWidth: Int, - rejectionHeight: Int, - frameWeights: FloatArray, - whiteBalanceGains: FloatArray, - inputBlackLevelsRgb: FloatArray, - inputBlackLevelsRggb: FloatArray, - inputGains: FloatArray, - overallGain: Float, - mergeSharpness: Float, - kernelSigmas: FloatArray, - rawWidth: Int, - rawHeight: Int, - outputWidth: Int, - outputHeight: Int, - outputStorageWidth: Int, - outputStorageHeight: Int, - cfaPattern: Int, - outputPlanarF16: ByteBuffer, - ): Int -} diff --git a/app/src/main/java/com/hinnka/mycamera/processor/MgcSpatialStrengthAtlasLayout.kt b/app/src/main/java/com/hinnka/mycamera/processor/MgcSpatialStrengthAtlasLayout.kt index 7cbdd79c..535948ec 100644 --- a/app/src/main/java/com/hinnka/mycamera/processor/MgcSpatialStrengthAtlasLayout.kt +++ b/app/src/main/java/com/hinnka/mycamera/processor/MgcSpatialStrengthAtlasLayout.kt @@ -62,33 +62,5 @@ internal fun createMgcSpatialStrengthAtlasLayout( } } -internal data class MgcSpatialStrengthPackDispatch( - val groupsX: Int, - val groupsY: Int, -) - -internal fun createMgcSpatialStrengthPackDispatch( - invocationCount: Long, - localSize: Int, - maximumGroupsX: Int, - maximumGroupsY: Int, -): MgcSpatialStrengthPackDispatch { - require(invocationCount > 0L) - require(localSize > 0 && maximumGroupsX > 0 && maximumGroupsY > 0) - val totalGroups = ceilDivPositive(invocationCount, localSize.toLong()) - require(totalGroups <= maximumGroupsX.toLong() * maximumGroupsY) { - "MGC Spatial strength pack requires $totalGroups work groups, device supports " + - "${maximumGroupsX}x$maximumGroupsY" - } - val groupsX = minOf(totalGroups, maximumGroupsX.toLong()).toInt() - return MgcSpatialStrengthPackDispatch( - groupsX = groupsX, - groupsY = ceilDivPositive(totalGroups, groupsX.toLong()).toInt(), - ) -} - private fun ceilDivPositive(value: Int, divisor: Int): Int = ((value.toLong() + divisor - 1L) / divisor).toInt() - -private fun ceilDivPositive(value: Long, divisor: Long): Long = - (value + divisor - 1L) / divisor diff --git a/app/src/main/java/com/hinnka/mycamera/processor/MgcStrengthReadbackShaders.kt b/app/src/main/java/com/hinnka/mycamera/processor/MgcStrengthReadbackShaders.kt deleted file mode 100644 index cbfbc1e2..00000000 --- a/app/src/main/java/com/hinnka/mycamera/processor/MgcStrengthReadbackShaders.kt +++ /dev/null @@ -1,154 +0,0 @@ -package com.hinnka.mycamera.processor - -/** Pack passes used for asynchronous diagnostic readback. */ -internal object MgcStrengthReadbackShaders { - /** Exact RGB camera-domain signed-Q14 signal, packed after the isolated RGB merge pass. */ - val RGB_FIXED16_FRAGMENT = """ - #version 300 es - precision highp float; - precision highp int; - uniform highp sampler2D uColorAndRWeight; - uniform highp sampler2D uGbWeights; - uniform int uChannel; - uniform vec3 uCameraDomainScale; - uniform ivec2 uSourceSize; - layout(location = 0) out highp int oFixed16; - - void main() { - ivec2 position = min(ivec2(gl_FragCoord.xy), uSourceSize - ivec2(1)); - vec4 colorAndR = texelFetch(uColorAndRWeight, position, 0); - vec2 gbWeights = texelFetch(uGbWeights, position, 0).rg; - vec3 semantic = colorAndR.rgb / max( - vec3(colorAndR.a, gbWeights.x, gbWeights.y), - vec3(1.0e-8) - ); - vec3 rgb = vec3( - semantic.r + semantic.g, - semantic.r, - semantic.r + semantic.b - ) * uCameraDomainScale; - oFixed16 = int(round( - clamp(max(rgb[uChannel], 0.0) * 16384.0, 0.0, 32767.0) - )); - } - """.trimIndent() - - val FLOAT32 = """ - #version 310 es - layout(local_size_x = 128) in; - precision highp float; - precision highp int; - uniform highp sampler2D uSource; - uniform ivec2 uPlaneSize; - uniform int uPlaneCount; - uniform int uAtlasColumns; - layout(std430, binding = 0) writeonly buffer OutputValues { - float values[]; - }; - - ivec2 atlasPosition(int index) { - int planeArea = uPlaneSize.x * uPlaneSize.y; - int plane = index / planeArea; - int localIndex = index - plane * planeArea; - ivec2 local = ivec2(localIndex % uPlaneSize.x, localIndex / uPlaneSize.x); - ivec2 tile = ivec2(plane % uAtlasColumns, plane / uAtlasColumns); - return tile * uPlaneSize + local; - } - - void main() { - int index = int( - gl_GlobalInvocationID.x + - gl_GlobalInvocationID.y * gl_NumWorkGroups.x * gl_WorkGroupSize.x - ); - int count = uPlaneSize.x * uPlaneSize.y * uPlaneCount; - if (index >= count) return; - values[index] = texelFetch(uSource, atlasPosition(index), 0).r; - } - """.trimIndent() - - val UNORM8 = """ - #version 310 es - layout(local_size_x = 128) in; - precision highp float; - precision highp int; - uniform highp sampler2D uSource; - uniform ivec2 uPlaneSize; - uniform int uPlaneCount; - uniform int uAtlasColumns; - layout(std430, binding = 0) writeonly buffer OutputWords { - uint words[]; - }; - - ivec2 atlasPosition(int index) { - int planeArea = uPlaneSize.x * uPlaneSize.y; - int plane = index / planeArea; - int localIndex = index - plane * planeArea; - ivec2 local = ivec2(localIndex % uPlaneSize.x, localIndex / uPlaneSize.x); - ivec2 tile = ivec2(plane % uAtlasColumns, plane / uAtlasColumns); - return tile * uPlaneSize + local; - } - - void main() { - int wordIndex = int( - gl_GlobalInvocationID.x + - gl_GlobalInvocationID.y * gl_NumWorkGroups.x * gl_WorkGroupSize.x - ); - int byteCount = uPlaneSize.x * uPlaneSize.y * uPlaneCount; - int first = wordIndex * 4; - if (first >= byteCount) return; - uint packed = 0u; - for (int lane = 0; lane < 4; ++lane) { - int index = first + lane; - if (index >= byteCount) break; - uint value = uint(round(clamp( - texelFetch(uSource, atlasPosition(index), 0).r, - 0.0, - 1.0 - ) * 255.0)); - packed |= value << uint(lane * 8); - } - words[wordIndex] = packed; - } - """.trimIndent() - - val SINT16 = """ - #version 310 es - layout(local_size_x = 128) in; - precision highp float; - precision highp int; - uniform highp isampler2D uSource; - uniform ivec2 uPlaneSize; - uniform int uPlaneCount; - uniform int uAtlasColumns; - layout(std430, binding = 0) writeonly buffer OutputWords { - uint words[]; - }; - - ivec2 atlasPosition(int index) { - int planeArea = uPlaneSize.x * uPlaneSize.y; - int plane = index / planeArea; - int localIndex = index - plane * planeArea; - ivec2 local = ivec2(localIndex % uPlaneSize.x, localIndex / uPlaneSize.x); - ivec2 tile = ivec2(plane % uAtlasColumns, plane / uAtlasColumns); - return tile * uPlaneSize + local; - } - - void main() { - int wordIndex = int( - gl_GlobalInvocationID.x + - gl_GlobalInvocationID.y * gl_NumWorkGroups.x * gl_WorkGroupSize.x - ); - int valueCount = uPlaneSize.x * uPlaneSize.y * uPlaneCount; - int first = wordIndex * 2; - if (first >= valueCount) return; - uint packed = 0u; - for (int lane = 0; lane < 2; ++lane) { - int index = first + lane; - if (index >= valueCount) break; - uint bits = uint(texelFetch(uSource, atlasPosition(index), 0).r) & 0xffffu; - packed |= bits << uint(lane * 16); - } - words[wordIndex] = packed; - } - """.trimIndent() -} diff --git a/app/src/test/java/com/hinnka/mycamera/processor/MgcSpatialDiagnosticGeometryTest.kt b/app/src/test/java/com/hinnka/mycamera/processor/MgcSpatialDiagnosticGeometryTest.kt index 88de614a..4b1929bb 100644 --- a/app/src/test/java/com/hinnka/mycamera/processor/MgcSpatialDiagnosticGeometryTest.kt +++ b/app/src/test/java/com/hinnka/mycamera/processor/MgcSpatialDiagnosticGeometryTest.kt @@ -18,19 +18,6 @@ class MgcSpatialDiagnosticGeometryTest { } } - @Test - fun rgbFixed16PlanesCoverTheFinalCompleteAotTile() { - val geometry = mgcSpatialDiagnosticGeometry( - outputMode = MgcSpatialOutputMode.RGB, - imageWidth = 4080, - imageHeight = 3064, - ) - - assertEquals(4080, geometry.fixed16Width) - assertEquals(3072, geometry.fixed16Height) - assertEquals(4080L * 3072L * 3L, geometry.fixed16SampleCount) - } - @Test fun rgbGeometryUsesOutputPixelsAndPlanarRgbSignal() { val geometry = mgcSpatialDiagnosticGeometry( @@ -43,9 +30,6 @@ class MgcSpatialDiagnosticGeometryTest { assertEquals(288, geometry.alignmentHeight) assertEquals(1530, geometry.rejectionWidth) assertEquals(1149, geometry.rejectionHeight) - assertEquals(6128, geometry.fixed16Width) - assertEquals(4608, geometry.fixed16Height) - assertEquals(6128L * 4608L * 3L, geometry.fixed16SampleCount) } @Test @@ -60,8 +44,5 @@ class MgcSpatialDiagnosticGeometryTest { assertEquals(383, geometry.alignmentHeight) assertEquals(1020, geometry.rejectionWidth) assertEquals(766, geometry.rejectionHeight) - assertEquals(2040, geometry.fixed16Width) - assertEquals(1536, geometry.fixed16Height) - assertEquals(2040L * 1536L * 4L, geometry.fixed16SampleCount) } } diff --git a/app/src/test/java/com/hinnka/mycamera/processor/MgcSpatialStrengthAtlasLayoutTest.kt b/app/src/test/java/com/hinnka/mycamera/processor/MgcSpatialStrengthAtlasLayoutTest.kt index 2c57e27a..93d50f08 100644 --- a/app/src/test/java/com/hinnka/mycamera/processor/MgcSpatialStrengthAtlasLayoutTest.kt +++ b/app/src/test/java/com/hinnka/mycamera/processor/MgcSpatialStrengthAtlasLayoutTest.kt @@ -39,19 +39,4 @@ class MgcSpatialStrengthAtlasLayoutTest { assertEquals(0, layout.originX(18)) assertEquals(13_788, layout.originY(18)) } - - @Test - fun rejectionPackDispatchWrapsAcrossTheDeviceGroupCountLimit() { - val valueCount = 2_040L * 1_532L * 19L - val invocationCount = (valueCount + 3L) / 4L - val dispatch = createMgcSpatialStrengthPackDispatch( - invocationCount = invocationCount, - localSize = GlesComputeWorkGroup.LINEAR_SIZE, - maximumGroupsX = 65_535, - maximumGroupsY = 65_535, - ) - - assertEquals(65_535, dispatch.groupsX) - assertEquals(2, dispatch.groupsY) - } }