feat: migrate MGC sharpen to GLES
This commit is contained in:
1 parent
f3921777e5
commit
18b5e84094
10 files changed
+464
-1150
No files matched your search
@@ -11,41 +11,6 @@ set(
|
||||
)
|
||||
option(PHOTON_ENABLE_DNG_JXL "Enable Adobe DNG SDK JPEG XL support" OFF)
|
||||
|
||||
set(
|
||||
MGC_SHARPEN_CAPSULE
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/mgc_denoise_static/mgc_sharpen_capsule.bin"
|
||||
)
|
||||
set(
|
||||
MGC_SHARPEN_CAPSULE_SHA256
|
||||
"733065cfec32ac752cc2088ea284b44a55b24a6171e5829f6971dcb098b1d7ce"
|
||||
)
|
||||
if(NOT EXISTS "${MGC_SHARPEN_CAPSULE}")
|
||||
message(
|
||||
FATAL_ERROR
|
||||
"MGC SharpenTo16Bit capsule is missing; restore the tracked "
|
||||
"mgc_denoise_static/mgc_sharpen_capsule.bin asset"
|
||||
)
|
||||
endif()
|
||||
file(SHA256 "${MGC_SHARPEN_CAPSULE}" MGC_SHARPEN_CAPSULE_ACTUAL_SHA256)
|
||||
if(NOT MGC_SHARPEN_CAPSULE_ACTUAL_SHA256 STREQUAL MGC_SHARPEN_CAPSULE_SHA256)
|
||||
message(FATAL_ERROR "MGC SharpenTo16Bit capsule hash mismatch")
|
||||
endif()
|
||||
set(
|
||||
MGC_SHARPEN_ASM
|
||||
"${CMAKE_CURRENT_BINARY_DIR}/mgc_sharpen_static.S"
|
||||
)
|
||||
configure_file(
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/mgc_denoise_static/mgc_sharpen_static.S.in"
|
||||
"${MGC_SHARPEN_ASM}"
|
||||
@ONLY
|
||||
)
|
||||
set_source_files_properties(
|
||||
"${MGC_SHARPEN_ASM}"
|
||||
PROPERTIES
|
||||
GENERATED TRUE
|
||||
OBJECT_DEPENDS "${MGC_SHARPEN_CAPSULE}"
|
||||
)
|
||||
|
||||
set(
|
||||
MGC_GUIDED_CAPSULE
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/mgc_denoise_static/mgc_guided_upsample_capsule.bin"
|
||||
@@ -394,7 +359,6 @@ add_library(my-native-lib SHARED
|
||||
mgc_denoise_static/mgc_raisr_driver.cpp
|
||||
mgc_denoise_static/mgc_polysharp_driver.cpp
|
||||
"${MGC_GUIDED_ASM}"
|
||||
"${MGC_SHARPEN_ASM}"
|
||||
"${MGC_RAISR_ASM}"
|
||||
"${MGC_RAISR_TABLES_ASM}"
|
||||
"${MGC_POLYSHARP_ASM}"
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Host wrappers of the MGC FinishRaw sharpen and GuidedUpsample AOT kernels.
|
||||
// Host wrappers of the MGC GuidedUpsample AOT kernels.
|
||||
#include "mgc_denoise_static.h"
|
||||
|
||||
#include <cmath>
|
||||
@@ -38,21 +38,6 @@ static_assert(offsetof(HalideBuffer, type) == 32);
|
||||
static_assert(offsetof(HalideBuffer, dimensions) == 36);
|
||||
static_assert(offsetof(HalideBuffer, dim) == 40);
|
||||
|
||||
using SharpenTo16BitFn = int (*)(
|
||||
void*,
|
||||
HalideBuffer*,
|
||||
HalideBuffer*,
|
||||
HalideBuffer*,
|
||||
HalideBuffer*,
|
||||
float);
|
||||
extern "C" int photon_mgc_sharpen_to_16_bit_halide(
|
||||
void*,
|
||||
HalideBuffer*,
|
||||
HalideBuffer*,
|
||||
HalideBuffer*,
|
||||
HalideBuffer*,
|
||||
float);
|
||||
|
||||
HalideBuffer MakeBuffer(
|
||||
void* host,
|
||||
HalideType type,
|
||||
@@ -72,74 +57,6 @@ HalideBuffer MakeBuffer(
|
||||
|
||||
} // namespace
|
||||
|
||||
int RunSharpenTo16Bit(
|
||||
const int16_t* input_yuv,
|
||||
int width,
|
||||
int height,
|
||||
const float curves[30],
|
||||
const float relative_corner_acutance_correction[3],
|
||||
float sharpen_attenuation_scale,
|
||||
uint16_t* output_interleaved_rgb) {
|
||||
if (input_yuv == nullptr || curves == nullptr ||
|
||||
relative_corner_acutance_correction == nullptr ||
|
||||
output_interleaved_rgb == nullptr || width <= 0 || height <= 0 ||
|
||||
!std::isfinite(sharpen_attenuation_scale)) {
|
||||
return -1;
|
||||
}
|
||||
const int pixel_count = width * height;
|
||||
const HalideDimension input_dimensions[] = {
|
||||
{0, width, 1, 0},
|
||||
{0, height, width, 0},
|
||||
{0, 3, pixel_count, 0},
|
||||
};
|
||||
const HalideDimension curve_dimensions[] = {
|
||||
{0, 1, 1, 0},
|
||||
{0, 5, 1, 0},
|
||||
{0, 3, 5, 0},
|
||||
{0, 2, 15, 0},
|
||||
};
|
||||
const HalideDimension correction_dimensions[] = {
|
||||
{0, 3, 1, 0},
|
||||
};
|
||||
const HalideDimension output_dimensions[] = {
|
||||
{0, width, 3, 0},
|
||||
// This AOT schedules two output rows per iteration, including its final tail.
|
||||
// Input bounds stay exact so the kernel applies its original edge extension.
|
||||
{0, (height + 1) & ~1, width * 3, 0},
|
||||
{0, 3, 1, 0},
|
||||
};
|
||||
HalideBuffer input_buffer = MakeBuffer(
|
||||
const_cast<int16_t*>(input_yuv),
|
||||
{0, 16, 1},
|
||||
3,
|
||||
input_dimensions);
|
||||
HalideBuffer curve_buffer = MakeBuffer(
|
||||
const_cast<float*>(curves),
|
||||
{2, 32, 1},
|
||||
4,
|
||||
curve_dimensions);
|
||||
HalideBuffer correction_buffer = MakeBuffer(
|
||||
const_cast<float*>(relative_corner_acutance_correction),
|
||||
{2, 32, 1},
|
||||
1,
|
||||
correction_dimensions);
|
||||
HalideBuffer output_buffer = MakeBuffer(
|
||||
output_interleaved_rgb,
|
||||
{1, 16, 1},
|
||||
3,
|
||||
output_dimensions);
|
||||
const auto function = reinterpret_cast<SharpenTo16BitFn>(
|
||||
&photon_mgc_sharpen_to_16_bit_halide);
|
||||
return function(
|
||||
nullptr,
|
||||
&input_buffer,
|
||||
&curve_buffer,
|
||||
&correction_buffer,
|
||||
&output_buffer,
|
||||
sharpen_attenuation_scale);
|
||||
}
|
||||
|
||||
|
||||
// V25 S16 guide uses the same padded Q14 linear YUV domain as FinishRaw.
|
||||
extern "C" int photon_mgc_box_downsample_s16(
|
||||
void*, HalideBuffer*, HalideBuffer*, int, HalideBuffer*);
|
||||
|
||||
@@ -4,23 +4,6 @@
|
||||
|
||||
namespace photon::mgc_denoise {
|
||||
|
||||
/**
|
||||
* Runs MGC 9.6.080's exact SharpenTo16BitHalide FinishRaw kernel.
|
||||
*
|
||||
* input_yuv must be the tone-mapped U12 YUV emitted by ProcessLowFrequency
|
||||
* and restored by GuidedUpsample, not the guide's signed-Q14 linear YUV.
|
||||
* Output storage must accommodate width * round_up(height, 2) * 3 uint16_t
|
||||
* values for the AOT's two-row tail; only the first height rows are consumed.
|
||||
*/
|
||||
int RunSharpenTo16Bit(
|
||||
const int16_t* input_yuv,
|
||||
int width,
|
||||
int height,
|
||||
const float curves[30],
|
||||
const float relative_corner_acutance_correction[3],
|
||||
float sharpen_attenuation_scale,
|
||||
uint16_t* output_interleaved_rgb);
|
||||
|
||||
/** V25 BoxDownsample: padded planar Q14 YUV; output dimensions divide by 2^log2_scale. */
|
||||
int RunGuidedBoxDownsample(const int16_t* linear_yuv, int width, int height,
|
||||
int log2_scale, int16_t* low_yuv);
|
||||
|
||||
Binary file not shown.
@@ -1,13 +1,9 @@
|
||||
#include "mgc_denoise_static.h"
|
||||
#include "mgc_sharpen_adapter.h"
|
||||
#include <GLES3/gl3.h>
|
||||
#include <algorithm>
|
||||
#include <android/log.h>
|
||||
#include <arm_neon.h>
|
||||
#include <chrono>
|
||||
#include <cmath>
|
||||
#include <jni.h>
|
||||
#include <limits>
|
||||
|
||||
namespace photon::mgc_denoise {
|
||||
namespace {
|
||||
@@ -175,71 +171,6 @@ void SharpenRgbToFloatRgba(const uint16_t *rgb, size_t count, float *rgba) {
|
||||
}
|
||||
} // namespace photon::mgc_denoise
|
||||
|
||||
extern "C" JNIEXPORT jint JNICALL
|
||||
Java_com_hinnka_mycamera_raw_MgcSharpen_nativeSharpenRgbaFloat(
|
||||
JNIEnv *env, jobject, jobject rgba_buffer, jobject scratch_buffer,
|
||||
jint width, jint height, jfloat snr, jfloat attenuation, jfloatArray curve_points) {
|
||||
using namespace photon::mgc_denoise;
|
||||
if (!rgba_buffer || !scratch_buffer || !curve_points || width <= 0 || height <= 0 ||
|
||||
!std::isfinite(snr) || snr < 0 || !std::isfinite(attenuation) ||
|
||||
attenuation < 0)
|
||||
return -1;
|
||||
const size_t count = size_t(width) * size_t(height);
|
||||
const size_t output_count =
|
||||
size_t(width) * ((size_t(height) + 1) & ~size_t(1));
|
||||
const size_t scratch_bytes = (count + output_count) * 6;
|
||||
if (scratch_bytes > size_t(std::numeric_limits<int>::max()))
|
||||
return -1;
|
||||
auto *rgba = static_cast<float *>(env->GetDirectBufferAddress(rgba_buffer));
|
||||
auto *yuv =
|
||||
static_cast<int16_t *>(env->GetDirectBufferAddress(scratch_buffer));
|
||||
if (!rgba || !yuv ||
|
||||
env->GetDirectBufferCapacity(rgba_buffer) < jlong(count * 4 * sizeof(float)) ||
|
||||
env->GetDirectBufferCapacity(scratch_buffer) < jlong(scratch_bytes))
|
||||
return -1;
|
||||
auto *rgb = reinterpret_cast<uint16_t *>(yuv + count * 3);
|
||||
// Curves are resolved once in Kotlin from Photon's local, named tuning table.
|
||||
// Halide layout: point + 5 * frequency + 15 * coordinate.
|
||||
if (env->GetArrayLength(curve_points) != 30)
|
||||
return -1;
|
||||
float curves[30];
|
||||
env->GetFloatArrayRegion(curve_points, 0, 30, curves);
|
||||
if (env->ExceptionCheck())
|
||||
return -1;
|
||||
for (int band = 0; band < 3; ++band) {
|
||||
for (int point = 0; point < 5; ++point) {
|
||||
const int index = point + 5 * band;
|
||||
const float x = curves[index], y = curves[index + 15];
|
||||
if (!std::isfinite(x) || !std::isfinite(y) || x < 0 || y < 0 ||
|
||||
(point == 0 && (x != 0 || y != 0)) ||
|
||||
(point > 0 && x <= curves[index - 1]))
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
constexpr float corner_correction[3] = {0, 0, 0};
|
||||
using Clock = std::chrono::steady_clock;
|
||||
const auto start = Clock::now();
|
||||
if (!SharpenFloatRgbaToYuv(rgba, count, yuv)) return -1;
|
||||
const auto converted = Clock::now();
|
||||
const int result = RunSharpenTo16Bit(
|
||||
yuv, width, height, curves, corner_correction, attenuation, rgb);
|
||||
if (result != 0)
|
||||
return result;
|
||||
const auto sharpened = Clock::now();
|
||||
SharpenRgbToFloatRgba(rgb, count, rgba);
|
||||
const auto finish = Clock::now();
|
||||
const auto ms = [](auto a, auto b) {
|
||||
return std::chrono::duration<double, std::milli>(b - a).count();
|
||||
};
|
||||
__android_log_print(
|
||||
ANDROID_LOG_INFO, "PLog_MgcSharpen",
|
||||
"MGC original sharpen %dx%d snr=%.6g attenuation=%.6g convertInMs=%.3f "
|
||||
"kernelMs=%.3f convertOutMs=%.3f totalNativeMs=%.3f",
|
||||
width, height, snr, attenuation, ms(start, converted),
|
||||
ms(converted, sharpened), ms(sharpened, finish), ms(start, finish));
|
||||
return 0;
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT jboolean JNICALL
|
||||
Java_com_hinnka_mycamera_raw_RawFloatTextureTransfer_nativeUpload(
|
||||
JNIEnv *, jobject, jint pbo, jint texture, jint width, jint height) {
|
||||
|
||||
@@ -1,589 +0,0 @@
|
||||
/* Generated mechanically from pinned MGC 9.6.080 V24 SharpenTo16BitHalide.
|
||||
* Do not edit; regenerate with
|
||||
* scripts/research/generate_mgc_sharpen_static_asm.py.
|
||||
*/
|
||||
|
||||
#if !defined(__aarch64__)
|
||||
#error "MGC GuidedUpsample sharpen static lift is arm64-only"
|
||||
#endif
|
||||
|
||||
.hidden photon_mgc_halide_error_5ef61ac
|
||||
.hidden photon_mgc_halide_error_5ef6294
|
||||
.hidden photon_mgc_halide_error_5ef636c
|
||||
.hidden photon_mgc_halide_error_5ef63f8
|
||||
.hidden photon_mgc_halide_error_5ef64dc
|
||||
.hidden photon_mgc_halide_error_5ef6568
|
||||
.hidden photon_mgc_halide_error_5ef6600
|
||||
.hidden photon_mgc_halide_error_5ef6794
|
||||
.hidden photon_mgc_halide_error_5ef6a74
|
||||
.hidden photon_mgc_halide_error_5ef6a94
|
||||
.hidden photon_mgc_halide_error_5ef6b6c
|
||||
.hidden photon_mgc_halide_error_5ef6bd8
|
||||
.hidden photon_mgc_halide_error_5ef6c38
|
||||
.hidden photon_mgc_halide_do_par_for
|
||||
.hidden photon_mgc_halide_free
|
||||
.hidden photon_mgc_halide_malloc
|
||||
.hidden photon_mgc_halide_trace
|
||||
|
||||
.section .text.photon_mgc.SharpenTo16BitHalide,"ax",@progbits
|
||||
.p2align 12
|
||||
.global photon_mgc_sharpen_to_16_bit_halide
|
||||
.hidden photon_mgc_sharpen_to_16_bit_halide
|
||||
.type photon_mgc_sharpen_to_16_bit_halide, %function
|
||||
photon_mgc_sharpen_page_4b77000:
|
||||
.incbin "@MGC_SHARPEN_CAPSULE@", 0x0, 0xf20
|
||||
photon_mgc_sharpen_address_4b77f20:
|
||||
.incbin "@MGC_SHARPEN_CAPSULE@", 0xf20, 0xe0
|
||||
photon_mgc_sharpen_page_4b78000:
|
||||
.incbin "@MGC_SHARPEN_CAPSULE@", 0x1000, 0x130
|
||||
bl photon_mgc_halide_malloc
|
||||
.incbin "@MGC_SHARPEN_CAPSULE@", 0x1130, 0x3c
|
||||
bl photon_mgc_halide_malloc
|
||||
.incbin "@MGC_SHARPEN_CAPSULE@", 0x116c, 0x230
|
||||
adrp x13, photon_mgc_sharpen_page_6b0000
|
||||
.incbin "@MGC_SHARPEN_CAPSULE@", 0x139c, 0x8
|
||||
adrp x13, photon_mgc_sharpen_page_6b2000
|
||||
.incbin "@MGC_SHARPEN_CAPSULE@", 0x13a4, 0x330
|
||||
bl photon_mgc_halide_malloc
|
||||
.incbin "@MGC_SHARPEN_CAPSULE@", 0x16d4, 0x51c
|
||||
bl photon_mgc_halide_free
|
||||
.incbin "@MGC_SHARPEN_CAPSULE@", 0x1bf0, 0x38
|
||||
bl photon_mgc_halide_malloc
|
||||
.incbin "@MGC_SHARPEN_CAPSULE@", 0x1c28, 0x2e0
|
||||
bl photon_mgc_halide_free
|
||||
.incbin "@MGC_SHARPEN_CAPSULE@", 0x1f08, 0x48
|
||||
bl photon_mgc_halide_malloc
|
||||
.incbin "@MGC_SHARPEN_CAPSULE@", 0x1f50, 0x8c
|
||||
photon_mgc_sharpen_page_4b79000:
|
||||
.incbin "@MGC_SHARPEN_CAPSULE@", 0x1fdc, 0x1000
|
||||
photon_mgc_sharpen_page_4b7a000:
|
||||
.incbin "@MGC_SHARPEN_CAPSULE@", 0x2fdc, 0x1000
|
||||
photon_mgc_sharpen_page_4b7b000:
|
||||
.incbin "@MGC_SHARPEN_CAPSULE@", 0x3fdc, 0xa34
|
||||
adrp x11, photon_mgc_sharpen_page_6b0000
|
||||
.incbin "@MGC_SHARPEN_CAPSULE@", 0x4a10, 0x8
|
||||
adrp x11, photon_mgc_sharpen_page_6b0000
|
||||
.incbin "@MGC_SHARPEN_CAPSULE@", 0x4a18, 0x5bc
|
||||
photon_mgc_sharpen_page_4b7c000:
|
||||
.incbin "@MGC_SHARPEN_CAPSULE@", 0x4fd4, 0x210
|
||||
adrp x15, photon_mgc_sharpen_page_6b0000
|
||||
.incbin "@MGC_SHARPEN_CAPSULE@", 0x51e4, 0x120
|
||||
adrp x15, photon_mgc_sharpen_page_6b0000
|
||||
.incbin "@MGC_SHARPEN_CAPSULE@", 0x5304, 0x120
|
||||
adrp x15, photon_mgc_sharpen_page_6a9000
|
||||
.incbin "@MGC_SHARPEN_CAPSULE@", 0x5424, 0x40c
|
||||
adrp x11, photon_mgc_sharpen_page_6a9000
|
||||
.incbin "@MGC_SHARPEN_CAPSULE@", 0x5830, 0x6c
|
||||
adrp x11, photon_mgc_sharpen_page_6bc000
|
||||
.incbin "@MGC_SHARPEN_CAPSULE@", 0x589c, 0x8
|
||||
adrp x11, photon_mgc_sharpen_page_6b9000
|
||||
.incbin "@MGC_SHARPEN_CAPSULE@", 0x58a4, 0x718
|
||||
photon_mgc_sharpen_page_4b7d000:
|
||||
.incbin "@MGC_SHARPEN_CAPSULE@", 0x5fbc, 0xbfc
|
||||
bl photon_mgc_halide_free
|
||||
.incbin "@MGC_SHARPEN_CAPSULE@", 0x6bb8, 0x30
|
||||
bl photon_mgc_halide_free
|
||||
.incbin "@MGC_SHARPEN_CAPSULE@", 0x6be8, 0x30
|
||||
bl photon_mgc_halide_malloc
|
||||
.incbin "@MGC_SHARPEN_CAPSULE@", 0x6c18, 0xc8
|
||||
bl photon_mgc_halide_malloc
|
||||
.incbin "@MGC_SHARPEN_CAPSULE@", 0x6ce0, 0x3c
|
||||
bl photon_mgc_halide_malloc
|
||||
.incbin "@MGC_SHARPEN_CAPSULE@", 0x6d1c, 0x28c
|
||||
photon_mgc_sharpen_page_4b7e000:
|
||||
.incbin "@MGC_SHARPEN_CAPSULE@", 0x6fa8, 0x54
|
||||
adrp x16, photon_mgc_sharpen_page_6b0000
|
||||
.incbin "@MGC_SHARPEN_CAPSULE@", 0x6ffc, 0x10
|
||||
adrp x14, photon_mgc_sharpen_page_6b2000
|
||||
.incbin "@MGC_SHARPEN_CAPSULE@", 0x700c, 0x628
|
||||
bl photon_mgc_halide_malloc
|
||||
.incbin "@MGC_SHARPEN_CAPSULE@", 0x7634, 0x968
|
||||
photon_mgc_sharpen_page_4b7f000:
|
||||
.incbin "@MGC_SHARPEN_CAPSULE@", 0x7f9c, 0x34
|
||||
bl photon_mgc_halide_free
|
||||
.incbin "@MGC_SHARPEN_CAPSULE@", 0x7fd0, 0x34
|
||||
bl photon_mgc_halide_malloc
|
||||
.incbin "@MGC_SHARPEN_CAPSULE@", 0x8004, 0x300
|
||||
bl photon_mgc_halide_free
|
||||
.incbin "@MGC_SHARPEN_CAPSULE@", 0x8304, 0x54
|
||||
bl photon_mgc_halide_malloc
|
||||
.incbin "@MGC_SHARPEN_CAPSULE@", 0x8358, 0xc34
|
||||
photon_mgc_sharpen_page_4b80000:
|
||||
.incbin "@MGC_SHARPEN_CAPSULE@", 0x8f8c, 0x1000
|
||||
photon_mgc_sharpen_page_4b81000:
|
||||
.incbin "@MGC_SHARPEN_CAPSULE@", 0x9f8c, 0x1000
|
||||
photon_mgc_sharpen_page_4b82000:
|
||||
.incbin "@MGC_SHARPEN_CAPSULE@", 0xaf8c, 0x1000
|
||||
photon_mgc_sharpen_page_4b83000:
|
||||
.incbin "@MGC_SHARPEN_CAPSULE@", 0xbf8c, 0x1000
|
||||
photon_mgc_sharpen_page_4b84000:
|
||||
.incbin "@MGC_SHARPEN_CAPSULE@", 0xcf8c, 0x1000
|
||||
photon_mgc_sharpen_page_4b85000:
|
||||
.incbin "@MGC_SHARPEN_CAPSULE@", 0xdf8c, 0xb4c
|
||||
adrp x8, photon_mgc_sharpen_page_6b0000
|
||||
.incbin "@MGC_SHARPEN_CAPSULE@", 0xead8, 0x4
|
||||
adrp x8, photon_mgc_sharpen_page_6b0000
|
||||
.incbin "@MGC_SHARPEN_CAPSULE@", 0xeadc, 0x4a8
|
||||
photon_mgc_sharpen_page_4b86000:
|
||||
.incbin "@MGC_SHARPEN_CAPSULE@", 0xef84, 0x370
|
||||
adrp x8, photon_mgc_sharpen_page_6b0000
|
||||
.incbin "@MGC_SHARPEN_CAPSULE@", 0xf2f4, 0x114
|
||||
adrp x8, photon_mgc_sharpen_page_6b0000
|
||||
.incbin "@MGC_SHARPEN_CAPSULE@", 0xf408, 0x118
|
||||
adrp x8, photon_mgc_sharpen_page_6a9000
|
||||
.incbin "@MGC_SHARPEN_CAPSULE@", 0xf520, 0x3c4
|
||||
adrp x9, photon_mgc_sharpen_page_6a9000
|
||||
.incbin "@MGC_SHARPEN_CAPSULE@", 0xf8e4, 0x94
|
||||
adrp x9, photon_mgc_sharpen_page_6bc000
|
||||
.incbin "@MGC_SHARPEN_CAPSULE@", 0xf978, 0x8
|
||||
adrp x9, photon_mgc_sharpen_page_6b9000
|
||||
.incbin "@MGC_SHARPEN_CAPSULE@", 0xf980, 0x5ec
|
||||
photon_mgc_sharpen_page_4b87000:
|
||||
.incbin "@MGC_SHARPEN_CAPSULE@", 0xff6c, 0x1000
|
||||
photon_mgc_sharpen_page_4b88000:
|
||||
.incbin "@MGC_SHARPEN_CAPSULE@", 0x10f6c, 0x150
|
||||
adrp x8, photon_mgc_sharpen_page_6b0000
|
||||
.incbin "@MGC_SHARPEN_CAPSULE@", 0x110bc, 0x8
|
||||
adrp x8, photon_mgc_sharpen_page_6b0000
|
||||
.incbin "@MGC_SHARPEN_CAPSULE@", 0x110c4, 0x7b8
|
||||
adrp x8, photon_mgc_sharpen_page_6b0000
|
||||
.incbin "@MGC_SHARPEN_CAPSULE@", 0x1187c, 0x120
|
||||
adrp x8, photon_mgc_sharpen_page_6b0000
|
||||
.incbin "@MGC_SHARPEN_CAPSULE@", 0x1199c, 0x120
|
||||
adrp x8, photon_mgc_sharpen_page_6a9000
|
||||
.incbin "@MGC_SHARPEN_CAPSULE@", 0x11abc, 0x440
|
||||
adrp x8, photon_mgc_sharpen_page_6a9000
|
||||
.incbin "@MGC_SHARPEN_CAPSULE@", 0x11efc, 0x58
|
||||
photon_mgc_sharpen_page_4b89000:
|
||||
.incbin "@MGC_SHARPEN_CAPSULE@", 0x11f54, 0x14
|
||||
adrp x8, photon_mgc_sharpen_page_6bc000
|
||||
.incbin "@MGC_SHARPEN_CAPSULE@", 0x11f68, 0x8
|
||||
adrp x8, photon_mgc_sharpen_page_6b9000
|
||||
.incbin "@MGC_SHARPEN_CAPSULE@", 0x11f70, 0xfdc
|
||||
photon_mgc_sharpen_page_4b8a000:
|
||||
.incbin "@MGC_SHARPEN_CAPSULE@", 0x12f4c, 0x350
|
||||
bl photon_mgc_halide_free
|
||||
.incbin "@MGC_SHARPEN_CAPSULE@", 0x1329c, 0x28
|
||||
bl photon_mgc_halide_free
|
||||
.incbin "@MGC_SHARPEN_CAPSULE@", 0x132c4, 0x38
|
||||
bl photon_mgc_halide_malloc
|
||||
.incbin "@MGC_SHARPEN_CAPSULE@", 0x132fc, 0xd8
|
||||
bl photon_mgc_halide_free
|
||||
.incbin "@MGC_SHARPEN_CAPSULE@", 0x133d4, 0x3c
|
||||
adrp x1, photon_mgc_sharpen_page_d5d000
|
||||
.incbin "@MGC_SHARPEN_CAPSULE@", 0x13410, 0x8
|
||||
adrp x2, photon_mgc_sharpen_page_d5d000
|
||||
.incbin "@MGC_SHARPEN_CAPSULE@", 0x13418, 0x4
|
||||
adrp x3, photon_mgc_sharpen_page_d5d000
|
||||
.incbin "@MGC_SHARPEN_CAPSULE@", 0x1341c, 0x4
|
||||
bl photon_mgc_halide_error_5ef6c38
|
||||
.incbin "@MGC_SHARPEN_CAPSULE@", 0x13420, 0x8
|
||||
adrp x1, photon_mgc_sharpen_page_d5d000
|
||||
.incbin "@MGC_SHARPEN_CAPSULE@", 0x13428, 0x8
|
||||
adrp x2, photon_mgc_sharpen_page_d5d000
|
||||
.incbin "@MGC_SHARPEN_CAPSULE@", 0x13430, 0x4
|
||||
adrp x3, photon_mgc_sharpen_page_d5d000
|
||||
.incbin "@MGC_SHARPEN_CAPSULE@", 0x13434, 0x4
|
||||
bl photon_mgc_halide_error_5ef6c38
|
||||
.incbin "@MGC_SHARPEN_CAPSULE@", 0x13438, 0x24
|
||||
adrp x1, photon_mgc_sharpen_page_d5d000
|
||||
.incbin "@MGC_SHARPEN_CAPSULE@", 0x1345c, 0x8
|
||||
adrp x2, photon_mgc_sharpen_page_d5d000
|
||||
.incbin "@MGC_SHARPEN_CAPSULE@", 0x13464, 0x4
|
||||
adrp x3, photon_mgc_sharpen_page_d5d000
|
||||
.incbin "@MGC_SHARPEN_CAPSULE@", 0x13468, 0x4
|
||||
bl photon_mgc_halide_error_5ef6c38
|
||||
.incbin "@MGC_SHARPEN_CAPSULE@", 0x1346c, 0x24
|
||||
adrp x1, photon_mgc_sharpen_page_d5d000
|
||||
.incbin "@MGC_SHARPEN_CAPSULE@", 0x13490, 0x28
|
||||
bl photon_mgc_halide_error_5ef64dc
|
||||
.incbin "@MGC_SHARPEN_CAPSULE@", 0x134b8, 0x34
|
||||
bl photon_mgc_halide_free
|
||||
.incbin "@MGC_SHARPEN_CAPSULE@", 0x134ec, 0x18
|
||||
adrp x1, photon_mgc_sharpen_page_d5d000
|
||||
.incbin "@MGC_SHARPEN_CAPSULE@", 0x13504, 0x8
|
||||
adrp x2, photon_mgc_sharpen_page_d5d000
|
||||
.incbin "@MGC_SHARPEN_CAPSULE@", 0x1350c, 0x4
|
||||
adrp x3, photon_mgc_sharpen_page_d5d000
|
||||
.incbin "@MGC_SHARPEN_CAPSULE@", 0x13510, 0x4
|
||||
bl photon_mgc_halide_error_5ef6c38
|
||||
.incbin "@MGC_SHARPEN_CAPSULE@", 0x13514, 0x1c
|
||||
adrp x1, photon_mgc_sharpen_page_d5d000
|
||||
.incbin "@MGC_SHARPEN_CAPSULE@", 0x13530, 0x14
|
||||
bl photon_mgc_halide_error_5ef64dc
|
||||
.incbin "@MGC_SHARPEN_CAPSULE@", 0x13544, 0x38
|
||||
adrp x1, photon_mgc_sharpen_page_d5d000
|
||||
.incbin "@MGC_SHARPEN_CAPSULE@", 0x1357c, 0x1c
|
||||
bl photon_mgc_halide_error_5ef64dc
|
||||
.incbin "@MGC_SHARPEN_CAPSULE@", 0x13598, 0x8
|
||||
adrp x1, photon_mgc_sharpen_page_d5d000
|
||||
.incbin "@MGC_SHARPEN_CAPSULE@", 0x135a0, 0xc
|
||||
bl photon_mgc_halide_error_5ef64dc
|
||||
.incbin "@MGC_SHARPEN_CAPSULE@", 0x135ac, 0x1c
|
||||
bl photon_mgc_halide_free
|
||||
.incbin "@MGC_SHARPEN_CAPSULE@", 0x135c8, 0x10
|
||||
bl photon_mgc_halide_free
|
||||
.incbin "@MGC_SHARPEN_CAPSULE@", 0x135d8, 0x3c
|
||||
bl photon_mgc_halide_free
|
||||
.incbin "@MGC_SHARPEN_CAPSULE@", 0x13614, 0x2c
|
||||
bl photon_mgc_halide_free
|
||||
.incbin "@MGC_SHARPEN_CAPSULE@", 0x13640, 0x2c
|
||||
bl photon_mgc_halide_free
|
||||
.incbin "@MGC_SHARPEN_CAPSULE@", 0x1366c, 0x2c
|
||||
bl photon_mgc_halide_free
|
||||
.incbin "@MGC_SHARPEN_CAPSULE@", 0x13698, 0x2c
|
||||
bl photon_mgc_halide_free
|
||||
.incbin "@MGC_SHARPEN_CAPSULE@", 0x136c4, 0x4c
|
||||
bl photon_mgc_halide_free
|
||||
.incbin "@MGC_SHARPEN_CAPSULE@", 0x13710, 0x1c
|
||||
adrp x1, photon_mgc_sharpen_page_d5d000
|
||||
.incbin "@MGC_SHARPEN_CAPSULE@", 0x1372c, 0x14
|
||||
bl photon_mgc_halide_error_5ef64dc
|
||||
.incbin "@MGC_SHARPEN_CAPSULE@", 0x13740, 0x20
|
||||
bl photon_mgc_halide_malloc
|
||||
.incbin "@MGC_SHARPEN_CAPSULE@", 0x13760, 0x1c
|
||||
adrp x1, photon_mgc_sharpen_page_d5d000
|
||||
.incbin "@MGC_SHARPEN_CAPSULE@", 0x1377c, 0x14
|
||||
bl photon_mgc_halide_error_5ef64dc
|
||||
.incbin "@MGC_SHARPEN_CAPSULE@", 0x13790, 0x48
|
||||
bl photon_mgc_halide_error_5ef6a74
|
||||
.incbin "@MGC_SHARPEN_CAPSULE@", 0x137d8, 0x18
|
||||
adrp x1, photon_mgc_sharpen_page_d5d000
|
||||
.incbin "@MGC_SHARPEN_CAPSULE@", 0x137f0, 0xc
|
||||
bl photon_mgc_halide_error_5ef64dc
|
||||
.incbin "@MGC_SHARPEN_CAPSULE@", 0x137fc, 0x8
|
||||
adrp x1, photon_mgc_sharpen_page_d5d000
|
||||
.incbin "@MGC_SHARPEN_CAPSULE@", 0x13804, 0x14
|
||||
bl photon_mgc_halide_error_5ef64dc
|
||||
.incbin "@MGC_SHARPEN_CAPSULE@", 0x13818, 0x24
|
||||
bl photon_mgc_halide_malloc
|
||||
.incbin "@MGC_SHARPEN_CAPSULE@", 0x1383c, 0x1c
|
||||
adrp x1, photon_mgc_sharpen_page_d5d000
|
||||
.incbin "@MGC_SHARPEN_CAPSULE@", 0x13858, 0x14
|
||||
bl photon_mgc_halide_error_5ef64dc
|
||||
.incbin "@MGC_SHARPEN_CAPSULE@", 0x1386c, 0x40
|
||||
bl photon_mgc_halide_error_5ef6a74
|
||||
.incbin "@MGC_SHARPEN_CAPSULE@", 0x138ac, 0x3c
|
||||
bl photon_mgc_halide_error_5ef6a74
|
||||
.incbin "@MGC_SHARPEN_CAPSULE@", 0x138e8, 0x40
|
||||
bl photon_mgc_halide_error_5ef6a74
|
||||
.incbin "@MGC_SHARPEN_CAPSULE@", 0x13928, 0x3c
|
||||
bl photon_mgc_halide_error_5ef6a74
|
||||
.incbin "@MGC_SHARPEN_CAPSULE@", 0x13964, 0x34
|
||||
photon_mgc_sharpen_address_4b8ab24:
|
||||
photon_mgc_sharpen_to_16_bit_halide:
|
||||
.incbin "@MGC_SHARPEN_CAPSULE@", 0x13998, 0xb8
|
||||
adrp x1, photon_mgc_sharpen_page_d5d000
|
||||
.incbin "@MGC_SHARPEN_CAPSULE@", 0x13a50, 0x20
|
||||
adrp x16, photon_mgc_sharpen_page_6ad000
|
||||
.incbin "@MGC_SHARPEN_CAPSULE@", 0x13a70, 0x1b0
|
||||
adrp x8, photon_mgc_sharpen_page_6ae000
|
||||
.incbin "@MGC_SHARPEN_CAPSULE@", 0x13c20, 0x10
|
||||
adrp x11, photon_mgc_sharpen_page_6b0000
|
||||
.incbin "@MGC_SHARPEN_CAPSULE@", 0x13c30, 0x60
|
||||
adrp x10, photon_mgc_sharpen_page_6a9000
|
||||
.incbin "@MGC_SHARPEN_CAPSULE@", 0x13c90, 0x44
|
||||
adrp x10, photon_mgc_sharpen_page_6a7000
|
||||
.incbin "@MGC_SHARPEN_CAPSULE@", 0x13cd4, 0x158
|
||||
adrp x13, photon_mgc_sharpen_page_6ad000
|
||||
.incbin "@MGC_SHARPEN_CAPSULE@", 0x13e2c, 0x18
|
||||
adrp x13, photon_mgc_sharpen_page_6b6000
|
||||
.incbin "@MGC_SHARPEN_CAPSULE@", 0x13e44, 0x10
|
||||
photon_mgc_sharpen_page_4b8b000:
|
||||
.incbin "@MGC_SHARPEN_CAPSULE@", 0x13e54, 0x34
|
||||
adrp x10, photon_mgc_sharpen_page_6aa000
|
||||
.incbin "@MGC_SHARPEN_CAPSULE@", 0x13e88, 0x64
|
||||
adrp x13, photon_mgc_sharpen_page_6b9000
|
||||
.incbin "@MGC_SHARPEN_CAPSULE@", 0x13eec, 0x8
|
||||
adrp x13, photon_mgc_sharpen_page_6b5000
|
||||
.incbin "@MGC_SHARPEN_CAPSULE@", 0x13ef4, 0x8
|
||||
adrp x13, photon_mgc_sharpen_page_6af000
|
||||
.incbin "@MGC_SHARPEN_CAPSULE@", 0x13efc, 0x4
|
||||
adrp x13, photon_mgc_sharpen_page_6b1000
|
||||
.incbin "@MGC_SHARPEN_CAPSULE@", 0x13f00, 0xb0
|
||||
adrp x13, photon_mgc_sharpen_page_6b4000
|
||||
.incbin "@MGC_SHARPEN_CAPSULE@", 0x13fb0, 0x4ec
|
||||
adrp x1, photon_mgc_sharpen_page_d5d000
|
||||
.incbin "@MGC_SHARPEN_CAPSULE@", 0x1449c, 0x3c
|
||||
adrp x1, photon_mgc_sharpen_page_d5d000
|
||||
.incbin "@MGC_SHARPEN_CAPSULE@", 0x144d8, 0x34
|
||||
adrp x1, photon_mgc_sharpen_page_d5d000
|
||||
.incbin "@MGC_SHARPEN_CAPSULE@", 0x1450c, 0x3c
|
||||
adrp x1, photon_mgc_sharpen_page_d5d000
|
||||
.incbin "@MGC_SHARPEN_CAPSULE@", 0x14548, 0x4
|
||||
adrp x3, photon_mgc_sharpen_page_d5d000
|
||||
.incbin "@MGC_SHARPEN_CAPSULE@", 0x1454c, 0x28
|
||||
adrp x1, photon_mgc_sharpen_page_d5d000
|
||||
.incbin "@MGC_SHARPEN_CAPSULE@", 0x14574, 0x2c
|
||||
adrp x1, photon_mgc_sharpen_page_d5d000
|
||||
.incbin "@MGC_SHARPEN_CAPSULE@", 0x145a0, 0x2c
|
||||
adrp x1, photon_mgc_sharpen_page_d5d000
|
||||
.incbin "@MGC_SHARPEN_CAPSULE@", 0x145cc, 0x40
|
||||
adrp x1, photon_mgc_sharpen_page_d5d000
|
||||
.incbin "@MGC_SHARPEN_CAPSULE@", 0x1460c, 0x4
|
||||
adrp x3, photon_mgc_sharpen_page_d5d000
|
||||
.incbin "@MGC_SHARPEN_CAPSULE@", 0x14610, 0x2c
|
||||
adrp x1, photon_mgc_sharpen_page_d5d000
|
||||
.incbin "@MGC_SHARPEN_CAPSULE@", 0x1463c, 0x34
|
||||
adrp x1, photon_mgc_sharpen_page_d5d000
|
||||
.incbin "@MGC_SHARPEN_CAPSULE@", 0x14670, 0x34
|
||||
adrp x1, photon_mgc_sharpen_page_d5d000
|
||||
.incbin "@MGC_SHARPEN_CAPSULE@", 0x146a4, 0x40
|
||||
adrp x1, photon_mgc_sharpen_page_d5d000
|
||||
.incbin "@MGC_SHARPEN_CAPSULE@", 0x146e4, 0x4
|
||||
adrp x3, photon_mgc_sharpen_page_d5d000
|
||||
.incbin "@MGC_SHARPEN_CAPSULE@", 0x146e8, 0x28
|
||||
adrp x1, photon_mgc_sharpen_page_d5d000
|
||||
.incbin "@MGC_SHARPEN_CAPSULE@", 0x14710, 0x28
|
||||
adrp x1, photon_mgc_sharpen_page_d5d000
|
||||
.incbin "@MGC_SHARPEN_CAPSULE@", 0x14738, 0x30
|
||||
adrp x1, photon_mgc_sharpen_page_d5d000
|
||||
.incbin "@MGC_SHARPEN_CAPSULE@", 0x14768, 0x308
|
||||
adrp x1, photon_mgc_sharpen_page_d5d000
|
||||
.incbin "@MGC_SHARPEN_CAPSULE@", 0x14a70, 0x3c
|
||||
adrp x1, photon_mgc_sharpen_page_d5d000
|
||||
.incbin "@MGC_SHARPEN_CAPSULE@", 0x14aac, 0x30
|
||||
adrp x1, photon_mgc_sharpen_page_d5d000
|
||||
.incbin "@MGC_SHARPEN_CAPSULE@", 0x14adc, 0x2c
|
||||
adrp x1, photon_mgc_sharpen_page_d5d000
|
||||
.incbin "@MGC_SHARPEN_CAPSULE@", 0x14b08, 0x24
|
||||
adrp x1, photon_mgc_sharpen_page_d5d000
|
||||
.incbin "@MGC_SHARPEN_CAPSULE@", 0x14b2c, 0x2c
|
||||
adrp x1, photon_mgc_sharpen_page_d5d000
|
||||
.incbin "@MGC_SHARPEN_CAPSULE@", 0x14b58, 0x24
|
||||
adrp x1, photon_mgc_sharpen_page_d5d000
|
||||
.incbin "@MGC_SHARPEN_CAPSULE@", 0x14b7c, 0x2c
|
||||
adrp x1, photon_mgc_sharpen_page_d5d000
|
||||
.incbin "@MGC_SHARPEN_CAPSULE@", 0x14ba8, 0x30
|
||||
adrp x26, photon_mgc_sharpen_page_d5d000
|
||||
.incbin "@MGC_SHARPEN_CAPSULE@", 0x14bd8, 0x4
|
||||
adrp x1, photon_mgc_sharpen_page_d5d000
|
||||
.incbin "@MGC_SHARPEN_CAPSULE@", 0x14bdc, 0x24
|
||||
bl photon_mgc_halide_trace
|
||||
.incbin "@MGC_SHARPEN_CAPSULE@", 0x14c00, 0x1c8
|
||||
photon_mgc_sharpen_page_4b8c000:
|
||||
.incbin "@MGC_SHARPEN_CAPSULE@", 0x14dc8, 0x3b0
|
||||
adrp x16, photon_mgc_sharpen_page_6ac000
|
||||
.incbin "@MGC_SHARPEN_CAPSULE@", 0x15178, 0x7c
|
||||
adrp x1, photon_mgc_sharpen_page_614f000
|
||||
.incbin "@MGC_SHARPEN_CAPSULE@", 0x151f4, 0x30
|
||||
bl photon_mgc_halide_do_par_for
|
||||
.incbin "@MGC_SHARPEN_CAPSULE@", 0x15224, 0x14
|
||||
adrp x1, photon_mgc_sharpen_page_d5d000
|
||||
.incbin "@MGC_SHARPEN_CAPSULE@", 0x15238, 0x20
|
||||
bl photon_mgc_halide_trace
|
||||
.incbin "@MGC_SHARPEN_CAPSULE@", 0x15258, 0x34
|
||||
adrp x1, photon_mgc_sharpen_page_d5d000
|
||||
.incbin "@MGC_SHARPEN_CAPSULE@", 0x1528c, 0x8
|
||||
adrp x1, photon_mgc_sharpen_page_d5d000
|
||||
.incbin "@MGC_SHARPEN_CAPSULE@", 0x15294, 0xc
|
||||
adrp x1, photon_mgc_sharpen_page_d5d000
|
||||
.incbin "@MGC_SHARPEN_CAPSULE@", 0x152a0, 0x30
|
||||
b photon_mgc_halide_error_5ef6a94
|
||||
adrp x1, photon_mgc_sharpen_page_d5d000
|
||||
.incbin "@MGC_SHARPEN_CAPSULE@", 0x152d0, 0x4
|
||||
adrp x2, photon_mgc_sharpen_page_d5d000
|
||||
.incbin "@MGC_SHARPEN_CAPSULE@", 0x152d4, 0x40
|
||||
b photon_mgc_halide_error_5ef61ac
|
||||
adrp x1, photon_mgc_sharpen_page_d5d000
|
||||
.incbin "@MGC_SHARPEN_CAPSULE@", 0x15314, 0x10
|
||||
adrp x1, photon_mgc_sharpen_page_d5d000
|
||||
.incbin "@MGC_SHARPEN_CAPSULE@", 0x15324, 0x14
|
||||
adrp x1, photon_mgc_sharpen_page_d5d000
|
||||
.incbin "@MGC_SHARPEN_CAPSULE@", 0x15338, 0xc
|
||||
adrp x1, photon_mgc_sharpen_page_d5d000
|
||||
.incbin "@MGC_SHARPEN_CAPSULE@", 0x15344, 0x10
|
||||
adrp x1, photon_mgc_sharpen_page_d5d000
|
||||
.incbin "@MGC_SHARPEN_CAPSULE@", 0x15354, 0x10
|
||||
adrp x1, photon_mgc_sharpen_page_d5d000
|
||||
.incbin "@MGC_SHARPEN_CAPSULE@", 0x15364, 0x10
|
||||
adrp x1, photon_mgc_sharpen_page_d5d000
|
||||
.incbin "@MGC_SHARPEN_CAPSULE@", 0x15374, 0x8
|
||||
adrp x1, photon_mgc_sharpen_page_d5d000
|
||||
.incbin "@MGC_SHARPEN_CAPSULE@", 0x1537c, 0x34
|
||||
b photon_mgc_halide_error_5ef6b6c
|
||||
adrp x1, photon_mgc_sharpen_page_d5d000
|
||||
.incbin "@MGC_SHARPEN_CAPSULE@", 0x153b0, 0x10
|
||||
adrp x1, photon_mgc_sharpen_page_d5d000
|
||||
.incbin "@MGC_SHARPEN_CAPSULE@", 0x153c0, 0x10
|
||||
adrp x1, photon_mgc_sharpen_page_d5d000
|
||||
.incbin "@MGC_SHARPEN_CAPSULE@", 0x153d0, 0x14
|
||||
adrp x1, photon_mgc_sharpen_page_d5d000
|
||||
.incbin "@MGC_SHARPEN_CAPSULE@", 0x153e4, 0x3c
|
||||
b photon_mgc_halide_error_5ef6600
|
||||
adrp x1, photon_mgc_sharpen_page_d5d000
|
||||
.incbin "@MGC_SHARPEN_CAPSULE@", 0x15420, 0x10
|
||||
adrp x1, photon_mgc_sharpen_page_d5d000
|
||||
.incbin "@MGC_SHARPEN_CAPSULE@", 0x15430, 0x3c
|
||||
b photon_mgc_halide_error_5ef64dc
|
||||
.incbin "@MGC_SHARPEN_CAPSULE@", 0x1546c, 0xc
|
||||
adrp x1, photon_mgc_sharpen_page_d5d000
|
||||
.incbin "@MGC_SHARPEN_CAPSULE@", 0x15478, 0x14
|
||||
adrp x1, photon_mgc_sharpen_page_d5d000
|
||||
.incbin "@MGC_SHARPEN_CAPSULE@", 0x1548c, 0x20
|
||||
adrp x1, photon_mgc_sharpen_page_d5d000
|
||||
.incbin "@MGC_SHARPEN_CAPSULE@", 0x154ac, 0x20
|
||||
adrp x1, photon_mgc_sharpen_page_d5d000
|
||||
.incbin "@MGC_SHARPEN_CAPSULE@", 0x154cc, 0x4
|
||||
adrp x3, photon_mgc_sharpen_page_d5d000
|
||||
.incbin "@MGC_SHARPEN_CAPSULE@", 0x154d0, 0x14
|
||||
adrp x1, photon_mgc_sharpen_page_d5d000
|
||||
.incbin "@MGC_SHARPEN_CAPSULE@", 0x154e4, 0x14
|
||||
adrp x1, photon_mgc_sharpen_page_d5d000
|
||||
.incbin "@MGC_SHARPEN_CAPSULE@", 0x154f8, 0x10
|
||||
adrp x1, photon_mgc_sharpen_page_d5d000
|
||||
.incbin "@MGC_SHARPEN_CAPSULE@", 0x15508, 0x14
|
||||
adrp x1, photon_mgc_sharpen_page_d5d000
|
||||
.incbin "@MGC_SHARPEN_CAPSULE@", 0x1551c, 0x4
|
||||
adrp x3, photon_mgc_sharpen_page_d5d000
|
||||
.incbin "@MGC_SHARPEN_CAPSULE@", 0x15520, 0x20
|
||||
adrp x1, photon_mgc_sharpen_page_d5d000
|
||||
.incbin "@MGC_SHARPEN_CAPSULE@", 0x15540, 0x34
|
||||
b photon_mgc_halide_error_5ef6294
|
||||
.incbin "@MGC_SHARPEN_CAPSULE@", 0x15574, 0x8
|
||||
adrp x1, photon_mgc_sharpen_page_d5d000
|
||||
.incbin "@MGC_SHARPEN_CAPSULE@", 0x1557c, 0x14
|
||||
adrp x1, photon_mgc_sharpen_page_d5d000
|
||||
.incbin "@MGC_SHARPEN_CAPSULE@", 0x15590, 0x24
|
||||
adrp x1, photon_mgc_sharpen_page_d5d000
|
||||
.incbin "@MGC_SHARPEN_CAPSULE@", 0x155b4, 0x14
|
||||
adrp x1, photon_mgc_sharpen_page_d5d000
|
||||
.incbin "@MGC_SHARPEN_CAPSULE@", 0x155c8, 0x14
|
||||
adrp x1, photon_mgc_sharpen_page_d5d000
|
||||
.incbin "@MGC_SHARPEN_CAPSULE@", 0x155dc, 0xc
|
||||
adrp x1, photon_mgc_sharpen_page_d5d000
|
||||
.incbin "@MGC_SHARPEN_CAPSULE@", 0x155e8, 0x4
|
||||
adrp x3, photon_mgc_sharpen_page_d5d000
|
||||
.incbin "@MGC_SHARPEN_CAPSULE@", 0x155ec, 0x18
|
||||
adrp x1, photon_mgc_sharpen_page_d5d000
|
||||
.incbin "@MGC_SHARPEN_CAPSULE@", 0x15604, 0x4
|
||||
adrp x3, photon_mgc_sharpen_page_d5d000
|
||||
.incbin "@MGC_SHARPEN_CAPSULE@", 0x15608, 0x14
|
||||
adrp x1, photon_mgc_sharpen_page_d5d000
|
||||
.incbin "@MGC_SHARPEN_CAPSULE@", 0x1561c, 0x34
|
||||
b photon_mgc_halide_error_5ef636c
|
||||
.incbin "@MGC_SHARPEN_CAPSULE@", 0x15650, 0x10
|
||||
adrp x1, photon_mgc_sharpen_page_d5d000
|
||||
.incbin "@MGC_SHARPEN_CAPSULE@", 0x15660, 0x20
|
||||
adrp x1, photon_mgc_sharpen_page_d5d000
|
||||
.incbin "@MGC_SHARPEN_CAPSULE@", 0x15680, 0x34
|
||||
b photon_mgc_halide_error_5ef6568
|
||||
.incbin "@MGC_SHARPEN_CAPSULE@", 0x156b4, 0xc
|
||||
adrp x1, photon_mgc_sharpen_page_d5d000
|
||||
.incbin "@MGC_SHARPEN_CAPSULE@", 0x156c0, 0x18
|
||||
adrp x1, photon_mgc_sharpen_page_d5d000
|
||||
.incbin "@MGC_SHARPEN_CAPSULE@", 0x156d8, 0x18
|
||||
adrp x1, photon_mgc_sharpen_page_d5d000
|
||||
.incbin "@MGC_SHARPEN_CAPSULE@", 0x156f0, 0x44
|
||||
b photon_mgc_halide_error_5ef63f8
|
||||
.incbin "@MGC_SHARPEN_CAPSULE@", 0x15734, 0x8
|
||||
adrp x1, photon_mgc_sharpen_page_d5d000
|
||||
.incbin "@MGC_SHARPEN_CAPSULE@", 0x1573c, 0x4
|
||||
adrp x3, photon_mgc_sharpen_page_d5d000
|
||||
.incbin "@MGC_SHARPEN_CAPSULE@", 0x15740, 0x14
|
||||
adrp x1, photon_mgc_sharpen_page_d5d000
|
||||
.incbin "@MGC_SHARPEN_CAPSULE@", 0x15754, 0x4
|
||||
adrp x3, photon_mgc_sharpen_page_d5d000
|
||||
.incbin "@MGC_SHARPEN_CAPSULE@", 0x15758, 0x10
|
||||
adrp x1, photon_mgc_sharpen_page_d5d000
|
||||
.incbin "@MGC_SHARPEN_CAPSULE@", 0x15768, 0x4
|
||||
adrp x3, photon_mgc_sharpen_page_d5d000
|
||||
.incbin "@MGC_SHARPEN_CAPSULE@", 0x1576c, 0x38
|
||||
b photon_mgc_halide_error_5ef6794
|
||||
adrp x1, photon_mgc_sharpen_page_d5d000
|
||||
.incbin "@MGC_SHARPEN_CAPSULE@", 0x157a4, 0x8
|
||||
adrp x1, photon_mgc_sharpen_page_d5d000
|
||||
.incbin "@MGC_SHARPEN_CAPSULE@", 0x157ac, 0x8
|
||||
adrp x1, photon_mgc_sharpen_page_d5d000
|
||||
.incbin "@MGC_SHARPEN_CAPSULE@", 0x157b4, 0x34
|
||||
b photon_mgc_halide_error_5ef6bd8
|
||||
.incbin "@MGC_SHARPEN_CAPSULE@", 0x157e8, 0x4c8
|
||||
|
||||
.section .rodata.photon_mgc.sharpen_page_6a7000,"a",@progbits
|
||||
.p2align 12
|
||||
photon_mgc_sharpen_page_6a7000:
|
||||
.incbin "@MGC_SHARPEN_CAPSULE@", 0x15cb0, 0x1000
|
||||
|
||||
.section .rodata.photon_mgc.sharpen_page_6a9000,"a",@progbits
|
||||
.p2align 12
|
||||
photon_mgc_sharpen_page_6a9000:
|
||||
.incbin "@MGC_SHARPEN_CAPSULE@", 0x16cb0, 0x1000
|
||||
|
||||
.section .rodata.photon_mgc.sharpen_page_6aa000,"a",@progbits
|
||||
.p2align 12
|
||||
photon_mgc_sharpen_page_6aa000:
|
||||
.incbin "@MGC_SHARPEN_CAPSULE@", 0x17cb0, 0x1000
|
||||
|
||||
.section .rodata.photon_mgc.sharpen_page_6ac000,"a",@progbits
|
||||
.p2align 12
|
||||
photon_mgc_sharpen_page_6ac000:
|
||||
.incbin "@MGC_SHARPEN_CAPSULE@", 0x18cb0, 0x1000
|
||||
|
||||
.section .rodata.photon_mgc.sharpen_page_6ad000,"a",@progbits
|
||||
.p2align 12
|
||||
photon_mgc_sharpen_page_6ad000:
|
||||
.incbin "@MGC_SHARPEN_CAPSULE@", 0x19cb0, 0x1000
|
||||
|
||||
.section .rodata.photon_mgc.sharpen_page_6ae000,"a",@progbits
|
||||
.p2align 12
|
||||
photon_mgc_sharpen_page_6ae000:
|
||||
.incbin "@MGC_SHARPEN_CAPSULE@", 0x1acb0, 0x1000
|
||||
|
||||
.section .rodata.photon_mgc.sharpen_page_6af000,"a",@progbits
|
||||
.p2align 12
|
||||
photon_mgc_sharpen_page_6af000:
|
||||
.incbin "@MGC_SHARPEN_CAPSULE@", 0x1bcb0, 0x1000
|
||||
|
||||
.section .rodata.photon_mgc.sharpen_page_6b0000,"a",@progbits
|
||||
.p2align 12
|
||||
photon_mgc_sharpen_page_6b0000:
|
||||
.incbin "@MGC_SHARPEN_CAPSULE@", 0x1ccb0, 0x1000
|
||||
|
||||
.section .rodata.photon_mgc.sharpen_page_6b1000,"a",@progbits
|
||||
.p2align 12
|
||||
photon_mgc_sharpen_page_6b1000:
|
||||
.incbin "@MGC_SHARPEN_CAPSULE@", 0x1dcb0, 0x1000
|
||||
|
||||
.section .rodata.photon_mgc.sharpen_page_6b2000,"a",@progbits
|
||||
.p2align 12
|
||||
photon_mgc_sharpen_page_6b2000:
|
||||
.incbin "@MGC_SHARPEN_CAPSULE@", 0x1ecb0, 0x1000
|
||||
|
||||
.section .rodata.photon_mgc.sharpen_page_6b4000,"a",@progbits
|
||||
.p2align 12
|
||||
photon_mgc_sharpen_page_6b4000:
|
||||
.incbin "@MGC_SHARPEN_CAPSULE@", 0x1fcb0, 0x1000
|
||||
|
||||
.section .rodata.photon_mgc.sharpen_page_6b5000,"a",@progbits
|
||||
.p2align 12
|
||||
photon_mgc_sharpen_page_6b5000:
|
||||
.incbin "@MGC_SHARPEN_CAPSULE@", 0x20cb0, 0x1000
|
||||
|
||||
.section .rodata.photon_mgc.sharpen_page_6b6000,"a",@progbits
|
||||
.p2align 12
|
||||
photon_mgc_sharpen_page_6b6000:
|
||||
.incbin "@MGC_SHARPEN_CAPSULE@", 0x21cb0, 0x1000
|
||||
|
||||
.section .rodata.photon_mgc.sharpen_page_6b9000,"a",@progbits
|
||||
.p2align 12
|
||||
photon_mgc_sharpen_page_6b9000:
|
||||
.incbin "@MGC_SHARPEN_CAPSULE@", 0x22cb0, 0x1000
|
||||
|
||||
.section .rodata.photon_mgc.sharpen_page_6bc000,"a",@progbits
|
||||
.p2align 12
|
||||
photon_mgc_sharpen_page_6bc000:
|
||||
.incbin "@MGC_SHARPEN_CAPSULE@", 0x23cb0, 0x1000
|
||||
|
||||
.section .rodata.photon_mgc.sharpen_page_d5d000,"a",@progbits
|
||||
.p2align 12
|
||||
photon_mgc_sharpen_page_d5d000:
|
||||
.incbin "@MGC_SHARPEN_CAPSULE@", 0x24cb0, 0x1000
|
||||
|
||||
.section .data.rel.ro.photon_mgc.sharpen_page_614f000,"aw",@progbits
|
||||
.p2align 12
|
||||
photon_mgc_sharpen_page_614f000:
|
||||
.incbin "@MGC_SHARPEN_CAPSULE@", 0x25cb0, 0xeb0
|
||||
.xword photon_mgc_sharpen_address_4b77f20
|
||||
.incbin "@MGC_SHARPEN_CAPSULE@", 0x26b60, 0x148
|
||||
|
||||
.section .note.GNU-stack,"",@progbits
|
||||
@@ -0,0 +1,242 @@
|
||||
package com.hinnka.mycamera.raw
|
||||
|
||||
import android.opengl.GLES30
|
||||
|
||||
/**
|
||||
* Runs [GlesMgcSharpenShaders] (MGC V24 SharpenTo16Bit) from an encoded RGBA16F texture into an
|
||||
* RGBA16F target, entirely on the GPU. Scratch planes are kept across frames of equal size.
|
||||
*/
|
||||
internal class GlesMgcSharpen {
|
||||
private val quad = RawFullscreenQuad()
|
||||
private var lumaProgram = 0
|
||||
private var level1Program = 0
|
||||
private var level2Program = 0
|
||||
private var outputProgram = 0
|
||||
private var width = 0
|
||||
private var height = 0
|
||||
private var lumaTexture = 0
|
||||
private var level1Texture = 0
|
||||
private var level2Texture = 0
|
||||
private var lumaFramebuffer = 0
|
||||
private var level1Framebuffer = 0
|
||||
private var level2Framebuffer = 0
|
||||
private var outputFramebuffer = 0
|
||||
|
||||
fun render(source: Int, target: Int, width: Int, height: Int, curves: FloatArray, attenuation: Float) {
|
||||
require(width > 0 && height > 0 && source != 0 && target != 0)
|
||||
require(attenuation.isFinite() && attenuation >= 0f)
|
||||
val uniforms = KernelUniforms(curves, width, height, attenuation)
|
||||
ensurePrograms()
|
||||
ensurePlanes(width, height)
|
||||
GLES30.glBindFramebuffer(GLES30.GL_FRAMEBUFFER, outputFramebuffer)
|
||||
GLES30.glFramebufferTexture2D(GLES30.GL_FRAMEBUFFER, GLES30.GL_COLOR_ATTACHMENT0,
|
||||
GLES30.GL_TEXTURE_2D, target, 0)
|
||||
check(GLES30.glCheckFramebufferStatus(GLES30.GL_FRAMEBUFFER) == GLES30.GL_FRAMEBUFFER_COMPLETE) {
|
||||
"MGC sharpen target framebuffer is incomplete"
|
||||
}
|
||||
val level1Padding = GlesMgcSharpenShaders.LEVEL1_PADDING
|
||||
val level2Padding = GlesMgcSharpenShaders.LEVEL2_PADDING
|
||||
|
||||
begin(lumaProgram, lumaFramebuffer, width, height)
|
||||
bindTexture(lumaProgram, "uSource", 0, source)
|
||||
GLES30.glUniform1ui(GLES30.glGetUniformLocation(lumaProgram, "uFloatFence"), 0)
|
||||
quad.draw(lumaProgram)
|
||||
|
||||
begin(level1Program, level1Framebuffer, width + 2 * level1Padding, height + 2 * level1Padding)
|
||||
bindTexture(level1Program, "uLuma", 0, lumaTexture)
|
||||
GLES30.glUniform2i(GLES30.glGetUniformLocation(level1Program, "uImageMax"), width - 1, height - 1)
|
||||
quad.draw(level1Program)
|
||||
|
||||
begin(level2Program, level2Framebuffer, width + 2 * level2Padding, height + 2 * level2Padding)
|
||||
bindTexture(level2Program, "uLevel1", 0, level1Texture)
|
||||
quad.draw(level2Program)
|
||||
|
||||
val program = outputProgram
|
||||
begin(program, outputFramebuffer, width, height)
|
||||
bindTexture(program, "uSource", 0, source)
|
||||
bindTexture(program, "uLuma", 1, lumaTexture)
|
||||
bindTexture(program, "uLevel1", 2, level1Texture)
|
||||
bindTexture(program, "uLevel2", 3, level2Texture)
|
||||
fun location(name: String) = GLES30.glGetUniformLocation(program, name)
|
||||
GLES30.glUniform2i(location("uImageMax"), width - 1, height - 1)
|
||||
GLES30.glUniform1ui(location("uFloatFence"), 0)
|
||||
GLES30.glUniform1iv(location("uKnots"), uniforms.knots.size, uniforms.knots, 0)
|
||||
GLES30.glUniform1iv(location("uSlopes"), uniforms.slopes.size, uniforms.slopes, 0)
|
||||
GLES30.glUniform1iv(location("uIntercepts"), uniforms.intercepts.size, uniforms.intercepts, 0)
|
||||
GLES30.glUniform1i(location("uRadialValid"), if (uniforms.radialValid) 1 else 0)
|
||||
GLES30.glUniform2i(location("uCenter"), width shr 1, height shr 1)
|
||||
GLES30.glUniform1f(location("uInverseMaxRadius2"), uniforms.inverseMaxRadius2)
|
||||
GLES30.glUniform1fv(location("uCorner"), 3, RELATIVE_CORNER_ACUTANCE_CORRECTION, 0)
|
||||
GLES30.glUniform1f(location("uLowerScale"), uniforms.lowerScale)
|
||||
GLES30.glUniform1f(location("uUpperScale"), uniforms.upperScale)
|
||||
quad.draw(program)
|
||||
|
||||
GLES30.glFramebufferTexture2D(GLES30.GL_FRAMEBUFFER, GLES30.GL_COLOR_ATTACHMENT0,
|
||||
GLES30.GL_TEXTURE_2D, 0, 0)
|
||||
GLES30.glBindFramebuffer(GLES30.GL_FRAMEBUFFER, 0)
|
||||
for (unit in 3 downTo 0) {
|
||||
GLES30.glActiveTexture(GLES30.GL_TEXTURE0 + unit)
|
||||
GLES30.glBindTexture(GLES30.GL_TEXTURE_2D, 0)
|
||||
}
|
||||
val error = GLES30.glGetError()
|
||||
check(error == GLES30.GL_NO_ERROR) { "MGC sharpen GLES passes failed: 0x${Integer.toHexString(error)}" }
|
||||
}
|
||||
|
||||
private fun begin(program: Int, framebuffer: Int, viewportWidth: Int, viewportHeight: Int) {
|
||||
GLES30.glBindFramebuffer(GLES30.GL_FRAMEBUFFER, framebuffer)
|
||||
GLES30.glViewport(0, 0, viewportWidth, viewportHeight)
|
||||
GLES30.glUseProgram(program)
|
||||
quad.bindIdentityTextureMatrix(program)
|
||||
}
|
||||
|
||||
private fun bindTexture(program: Int, name: String, unit: Int, texture: Int) {
|
||||
GLES30.glActiveTexture(GLES30.GL_TEXTURE0 + unit)
|
||||
GLES30.glBindTexture(GLES30.GL_TEXTURE_2D, texture)
|
||||
GLES30.glUniform1i(GLES30.glGetUniformLocation(program, name), unit)
|
||||
}
|
||||
|
||||
private fun ensurePrograms() {
|
||||
if (outputProgram != 0) return
|
||||
try {
|
||||
lumaProgram = link(GlesMgcSharpenShaders.lumaShader, "MgcSharpenLuma")
|
||||
level1Program = link(GlesMgcSharpenShaders.level1Shader, "MgcSharpenLevel1")
|
||||
level2Program = link(GlesMgcSharpenShaders.level2Shader, "MgcSharpenLevel2")
|
||||
outputProgram = link(GlesMgcSharpenShaders.outputShader, "MgcSharpenOutput")
|
||||
} catch (error: Throwable) {
|
||||
releasePrograms()
|
||||
throw error
|
||||
}
|
||||
}
|
||||
|
||||
private fun link(source: String, name: String): Int =
|
||||
quad.createProgram(source, name).also { check(it != 0) { "Failed to link $name" } }
|
||||
|
||||
private fun ensurePlanes(width: Int, height: Int) {
|
||||
if (width == this.width && height == this.height && lumaTexture != 0) return
|
||||
releaseBuffers()
|
||||
try {
|
||||
val level1Padding = 2 * GlesMgcSharpenShaders.LEVEL1_PADDING
|
||||
val level2Padding = 2 * GlesMgcSharpenShaders.LEVEL2_PADDING
|
||||
lumaTexture = createPlane(width, height)
|
||||
level1Texture = createPlane(width + level1Padding, height + level1Padding)
|
||||
level2Texture = createPlane(width + level2Padding, height + level2Padding)
|
||||
lumaFramebuffer = createFramebuffer(lumaTexture)
|
||||
level1Framebuffer = createFramebuffer(level1Texture)
|
||||
level2Framebuffer = createFramebuffer(level2Texture)
|
||||
outputFramebuffer = IntArray(1).also { GLES30.glGenFramebuffers(1, it, 0) }[0]
|
||||
this.width = width
|
||||
this.height = height
|
||||
} catch (error: Throwable) {
|
||||
releaseBuffers()
|
||||
throw error
|
||||
}
|
||||
}
|
||||
|
||||
// Integer textures are incomplete under linear filtering, so texelFetch would read zero.
|
||||
private fun createPlane(width: Int, height: Int): Int {
|
||||
val names = IntArray(1)
|
||||
GLES30.glGenTextures(1, names, 0)
|
||||
GLES30.glBindTexture(GLES30.GL_TEXTURE_2D, names[0])
|
||||
GLES30.glTexParameteri(GLES30.GL_TEXTURE_2D, GLES30.GL_TEXTURE_MIN_FILTER, GLES30.GL_NEAREST)
|
||||
GLES30.glTexParameteri(GLES30.GL_TEXTURE_2D, GLES30.GL_TEXTURE_MAG_FILTER, GLES30.GL_NEAREST)
|
||||
GLES30.glTexParameteri(GLES30.GL_TEXTURE_2D, GLES30.GL_TEXTURE_WRAP_S, GLES30.GL_CLAMP_TO_EDGE)
|
||||
GLES30.glTexParameteri(GLES30.GL_TEXTURE_2D, GLES30.GL_TEXTURE_WRAP_T, GLES30.GL_CLAMP_TO_EDGE)
|
||||
GLES30.glTexStorage2D(GLES30.GL_TEXTURE_2D, 1, GLES30.GL_R16I, width, height)
|
||||
GLES30.glBindTexture(GLES30.GL_TEXTURE_2D, 0)
|
||||
val error = GLES30.glGetError()
|
||||
if (error != GLES30.GL_NO_ERROR) {
|
||||
GLES30.glDeleteTextures(1, names, 0)
|
||||
error("MGC sharpen R16I plane ${width}x$height failed: 0x${Integer.toHexString(error)}")
|
||||
}
|
||||
return names[0]
|
||||
}
|
||||
|
||||
private fun createFramebuffer(texture: Int): Int {
|
||||
val names = IntArray(1)
|
||||
GLES30.glGenFramebuffers(1, names, 0)
|
||||
GLES30.glBindFramebuffer(GLES30.GL_FRAMEBUFFER, names[0])
|
||||
GLES30.glFramebufferTexture2D(GLES30.GL_FRAMEBUFFER, GLES30.GL_COLOR_ATTACHMENT0,
|
||||
GLES30.GL_TEXTURE_2D, texture, 0)
|
||||
val status = GLES30.glCheckFramebufferStatus(GLES30.GL_FRAMEBUFFER)
|
||||
GLES30.glBindFramebuffer(GLES30.GL_FRAMEBUFFER, 0)
|
||||
if (status != GLES30.GL_FRAMEBUFFER_COMPLETE) {
|
||||
GLES30.glDeleteFramebuffers(1, names, 0)
|
||||
error("MGC sharpen R16I framebuffer is incomplete: 0x${Integer.toHexString(status)}")
|
||||
}
|
||||
return names[0]
|
||||
}
|
||||
|
||||
fun releaseBuffers() {
|
||||
val framebuffers = intArrayOf(lumaFramebuffer, level1Framebuffer, level2Framebuffer, outputFramebuffer)
|
||||
.filter { it != 0 }.toIntArray()
|
||||
if (framebuffers.isNotEmpty()) GLES30.glDeleteFramebuffers(framebuffers.size, framebuffers, 0)
|
||||
val textures = intArrayOf(lumaTexture, level1Texture, level2Texture).filter { it != 0 }.toIntArray()
|
||||
if (textures.isNotEmpty()) GLES30.glDeleteTextures(textures.size, textures, 0)
|
||||
lumaFramebuffer = 0; level1Framebuffer = 0; level2Framebuffer = 0; outputFramebuffer = 0
|
||||
lumaTexture = 0; level1Texture = 0; level2Texture = 0
|
||||
width = 0; height = 0
|
||||
}
|
||||
|
||||
private fun releasePrograms() {
|
||||
for (program in intArrayOf(lumaProgram, level1Program, level2Program, outputProgram)) {
|
||||
if (program != 0) GLES30.glDeleteProgram(program)
|
||||
}
|
||||
lumaProgram = 0; level1Program = 0; level2Program = 0; outputProgram = 0
|
||||
}
|
||||
|
||||
fun release() {
|
||||
releaseBuffers()
|
||||
releasePrograms()
|
||||
}
|
||||
|
||||
/**
|
||||
* The AOT entry's curve preparation, in the same unfused binary32 order (JVM Float arithmetic
|
||||
* is never contracted): knots and y values become int16 U12 codes, then each of the four
|
||||
* segments gets a Q8 slope and an intercept. Curves use [MgcSharpenCurveBuilder]'s
|
||||
* [point, frequency, coordinate] layout.
|
||||
*/
|
||||
class KernelUniforms(curves: FloatArray, width: Int, height: Int, attenuation: Float) {
|
||||
val knots = IntArray(9)
|
||||
val slopes = IntArray(12)
|
||||
val intercepts = IntArray(12)
|
||||
val radialValid: Boolean
|
||||
val inverseMaxRadius2: Float
|
||||
val lowerScale = 1f - attenuation
|
||||
val upperScale = attenuation + 1f
|
||||
|
||||
init {
|
||||
require(curves.size == 30)
|
||||
for (band in 0..2) {
|
||||
val knot = IntArray(5) { toS16(curves[5 * band + it] * 4095f) }
|
||||
val y = IntArray(5) { toS16(curves[15 + 5 * band + it] * 4095f) }
|
||||
for (i in 1..3) knots[band * 3 + i - 1] = knot[i]
|
||||
for (k in 0..3) {
|
||||
val dx = (knot[k + 1] - knot[k]).toShort().toInt().coerceAtLeast(1)
|
||||
val dy = (y[k + 1] - y[k]).toShort().toInt()
|
||||
val slope = dy.toFloat() / dx.toFloat()
|
||||
val slopeX0 = slope * knot[k].toFloat()
|
||||
val slopeQ8 = slope * 256f
|
||||
val intercept = y[k].toFloat() - slopeX0
|
||||
slopes[band * 4 + k] = toS16(slopeQ8)
|
||||
intercepts[band * 4 + k] = toS16(intercept)
|
||||
}
|
||||
}
|
||||
val halfWidth = width shr 1
|
||||
val halfHeight = height shr 1
|
||||
val maxRadius2 = (halfWidth * halfWidth).toFloat() + (halfHeight * halfHeight).toFloat()
|
||||
radialValid = maxRadius2 > 0f
|
||||
inverseMaxRadius2 = if (radialValid) 1f / maxRadius2 else 0f
|
||||
}
|
||||
|
||||
// Round half to even, clamp to int16 (NaN -> 0), truncate.
|
||||
private fun toS16(value: Float): Int {
|
||||
if (value.isNaN()) return 0
|
||||
return Math.rint(value.toDouble()).toFloat().coerceIn(-32768f, 32767f).toInt().toShort().toInt()
|
||||
}
|
||||
}
|
||||
|
||||
private companion object {
|
||||
// FinishRaw's relative corner acutance correction; the original call site passes zeros.
|
||||
val RELATIVE_CORNER_ACUTANCE_CORRECTION = floatArrayOf(0f, 0f, 0f)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,216 @@
|
||||
package com.hinnka.mycamera.raw
|
||||
|
||||
/**
|
||||
* Bit-exact GLES translation of MGC 9.6.080 V24 `gcam::SharpenTo16BitHalide` (libgcastartup.so
|
||||
* entry 0x4B77000) together with the former CPU adapters around it: RGBA16F encoded RGB -> U12
|
||||
* YUV before the kernel and U12 RGB -> RGBA16F after it. The independent reference, the algorithm
|
||||
* notes and the oracle that checks these shaders against the original AOT live in tools/mgc_sharpen.
|
||||
*
|
||||
* The kernel sharpens Y only, on an undecimated binomial pyramid with dilations 1, 2 and 4:
|
||||
*
|
||||
* 1. `luma`: encoded RGB -> U12 Y (R16I, image size).
|
||||
* 2. `level1`: L1 = blur(clamped Y, 1), stored over the image grown by [LEVEL1_PADDING] per side.
|
||||
* 3. `level2`: L2 = blur(L1, 2), stored over the image grown by [LEVEL2_PADDING] per side.
|
||||
* 4. `output`: L3 = blur(L2, 4), band curves, corner gain, 5x5 overshoot clamp and Q12 YUV -> RGB.
|
||||
*
|
||||
* Only Y is clamped at the image border (repeat edge); L1 and L2 outside the image are their
|
||||
* natural extension, which is why they keep a halo instead of being clamped.
|
||||
*/
|
||||
internal object GlesMgcSharpenShaders {
|
||||
const val LEVEL1_PADDING = 6
|
||||
const val LEVEL2_PADDING = 4
|
||||
|
||||
private val header = """
|
||||
#version 300 es
|
||||
precision highp float;
|
||||
precision highp int;
|
||||
precision highp sampler2D;
|
||||
precision highp isampler2D;
|
||||
""".trimIndent()
|
||||
|
||||
private val integerOps = """
|
||||
const int LEVEL1_PADDING = $LEVEL1_PADDING;
|
||||
const int LEVEL2_PADDING = $LEVEL2_PADDING;
|
||||
|
||||
int s16(int v) { return (v << 16) >> 16; }
|
||||
// SHADD / SRHADD .8h; inputs are int16 so the halved sums never wrap.
|
||||
int hadd(int a, int b) { return (a + b) >> 1; }
|
||||
int rhadd(int a, int b) { return (a + b + 1) >> 1; }
|
||||
""".trimIndent()
|
||||
|
||||
// GLSL ES has no `precise`. XOR with a zero uniform forces each product to be rounded to binary32
|
||||
// before it is added, as the original's separate FMUL/FADD do.
|
||||
private val floatOps = """
|
||||
uniform uint uFloatFence;
|
||||
|
||||
float fenced(float value) { return uintBitsToFloat(floatBitsToUint(value) ^ uFloatFence); }
|
||||
|
||||
float unitToU12(float value) { return fenced(clamp(value, 0.0, 1.0) * 4095.0); }
|
||||
|
||||
// One row of the FinishRaw U12 matrix, rounded half to even and clamped to +-4095.
|
||||
int u12Row(float r, float g, float b, float m0, float m1, float m2) {
|
||||
float partial = fenced(fenced(r * m0) + fenced(g * m1));
|
||||
return clamp(int(roundEven(partial + fenced(b * m2))), -4095, 4095);
|
||||
}
|
||||
""".trimIndent()
|
||||
|
||||
private val luma = """
|
||||
uniform highp sampler2D uSource;
|
||||
layout(location = 0) out int oLuma;
|
||||
|
||||
void main() {
|
||||
vec4 color = texelFetch(uSource, ivec2(gl_FragCoord.xy), 0);
|
||||
oLuma = u12Row(unitToU12(color.r), unitToU12(color.g), unitToU12(color.b),
|
||||
0.2125999927520752, 0.7152000069618225, 0.07219959795475006);
|
||||
}
|
||||
""".trimIndent()
|
||||
|
||||
private val level1 = """
|
||||
uniform highp isampler2D uLuma;
|
||||
uniform ivec2 uImageMax;
|
||||
layout(location = 0) out int oLevel;
|
||||
|
||||
int luma(ivec2 p) { return texelFetch(uLuma, clamp(p, ivec2(0), uImageMax), 0).r; }
|
||||
|
||||
int column(ivec2 p) {
|
||||
return rhadd(hadd(luma(p - ivec2(0, 1)), luma(p + ivec2(0, 1))), luma(p));
|
||||
}
|
||||
|
||||
void main() {
|
||||
ivec2 p = ivec2(gl_FragCoord.xy) - ivec2(LEVEL1_PADDING);
|
||||
oLevel = hadd(rhadd(column(p - ivec2(1, 0)), column(p + ivec2(1, 0))), column(p));
|
||||
}
|
||||
""".trimIndent()
|
||||
|
||||
private val level2 = """
|
||||
uniform highp isampler2D uLevel1;
|
||||
layout(location = 0) out int oLevel;
|
||||
|
||||
int level1(ivec2 p) { return texelFetch(uLevel1, p + ivec2(LEVEL1_PADDING), 0).r; }
|
||||
|
||||
int column(ivec2 p) {
|
||||
return rhadd(hadd(level1(p - ivec2(0, 2)), level1(p + ivec2(0, 2))), level1(p));
|
||||
}
|
||||
|
||||
void main() {
|
||||
ivec2 p = ivec2(gl_FragCoord.xy) - ivec2(LEVEL2_PADDING);
|
||||
oLevel = hadd(rhadd(column(p - ivec2(2, 0)), column(p + ivec2(2, 0))), column(p));
|
||||
}
|
||||
""".trimIndent()
|
||||
|
||||
private val output = """
|
||||
uniform highp sampler2D uSource;
|
||||
uniform highp isampler2D uLuma;
|
||||
uniform highp isampler2D uLevel1;
|
||||
uniform highp isampler2D uLevel2;
|
||||
uniform ivec2 uImageMax;
|
||||
// Per band: knots 1..3 (U12), then four segment slopes (Q8) and intercepts (U12).
|
||||
uniform int uKnots[9];
|
||||
uniform int uSlopes[12];
|
||||
uniform int uIntercepts[12];
|
||||
// 0 for a 1x1 image, whose radial term is NaN in the original and zeroes every band.
|
||||
uniform int uRadialValid;
|
||||
uniform ivec2 uCenter;
|
||||
uniform float uInverseMaxRadius2;
|
||||
uniform float uCorner[3];
|
||||
uniform float uLowerScale;
|
||||
uniform float uUpperScale;
|
||||
layout(location = 0) out vec4 oColor;
|
||||
|
||||
int luma(ivec2 p) { return texelFetch(uLuma, clamp(p, ivec2(0), uImageMax), 0).r; }
|
||||
int level1(ivec2 p) { return texelFetch(uLevel1, p + ivec2(LEVEL1_PADDING), 0).r; }
|
||||
int level2(ivec2 p) { return texelFetch(uLevel2, p + ivec2(LEVEL2_PADDING), 0).r; }
|
||||
|
||||
int column(ivec2 p) {
|
||||
return rhadd(hadd(level2(p - ivec2(0, 4)), level2(p + ivec2(0, 4))), level2(p));
|
||||
}
|
||||
|
||||
// Segment by |d| (int16 abs: -32768 stays negative), slope on the signed d, mirrored intercept.
|
||||
int curve(int band, int d) {
|
||||
int magnitude = s16(abs(d));
|
||||
int knot = band * 3;
|
||||
int segment = magnitude >= uKnots[knot + 2] ? 3
|
||||
: magnitude >= uKnots[knot + 1] ? 2
|
||||
: magnitude >= uKnots[knot] ? 1 : 0;
|
||||
int index = band * 4 + segment;
|
||||
int scaled = clamp((uSlopes[index] * d) >> 8, -32768, 32767);
|
||||
int intercept = d < 0 ? s16(-uIntercepts[index]) : uIntercepts[index];
|
||||
return s16(scaled + intercept);
|
||||
}
|
||||
|
||||
// FCVTZS to int32 (truncate, saturate) narrowed to int16.
|
||||
int truncateS16(float value) {
|
||||
if (value >= 2147483648.0) return -1;
|
||||
if (value <= -2147483648.0) return 0;
|
||||
return s16(int(value));
|
||||
}
|
||||
|
||||
int bandTerm(int band, int d, float radius2) {
|
||||
int shaped = curve(band, d);
|
||||
if (uRadialValid == 0) return 0;
|
||||
float gain = fenced(radius2 * uCorner[band]) + 1.0;
|
||||
return truncateS16(fenced(gain * float(shaped)));
|
||||
}
|
||||
|
||||
int overshootBound(int value, float scale) {
|
||||
return s16(int(clamp(float(value) * scale, -32768.0, 32767.0)));
|
||||
}
|
||||
|
||||
// Exact binary16 value of RNE(v / 4095), the former float division followed by an RNE half
|
||||
// conversion, so the attachment write does not depend on the driver's float -> half rounding.
|
||||
float u12ToUnit(int v) {
|
||||
if (v == 0) return 0.0;
|
||||
int shift = 12 - findMSB(v);
|
||||
if ((v << shift) >= 8190) shift -= 1;
|
||||
int numerator = v << (shift + 10);
|
||||
int quotient = numerator / 4095;
|
||||
if (2 * (numerator - quotient * 4095) > 4095) quotient += 1;
|
||||
return float(quotient) * uintBitsToFloat(uint(117 - shift) << 23);
|
||||
}
|
||||
|
||||
void main() {
|
||||
ivec2 p = ivec2(gl_FragCoord.xy);
|
||||
int y0 = texelFetch(uLuma, p, 0).r;
|
||||
int y1 = level1(p);
|
||||
int y2 = level2(p);
|
||||
int y3 = hadd(rhadd(column(p - ivec2(4, 0)), column(p + ivec2(4, 0))), column(p));
|
||||
|
||||
float dx = float(p.x - uCenter.x);
|
||||
float dy = float(p.y - uCenter.y);
|
||||
float radius2 = fenced(fenced(dy * dy) + fenced(dx * dx)) * uInverseMaxRadius2;
|
||||
int sharp = s16(y3 + bandTerm(0, s16(y0 - y1), radius2)
|
||||
+ bandTerm(1, s16(y1 - y2), radius2) + bandTerm(2, s16(y2 - y3), radius2));
|
||||
|
||||
int lowest = y0;
|
||||
int highest = y0;
|
||||
for (int j = -2; j <= 2; ++j) {
|
||||
for (int i = -2; i <= 2; ++i) {
|
||||
int neighbour = luma(p + ivec2(i, j));
|
||||
lowest = min(lowest, neighbour);
|
||||
highest = max(highest, neighbour);
|
||||
}
|
||||
}
|
||||
sharp = max(overshootBound(lowest, uLowerScale),
|
||||
min(overshootBound(highest, uUpperScale), sharp));
|
||||
sharp = clamp(sharp, 0, 4095);
|
||||
|
||||
vec4 color = texelFetch(uSource, p, 0);
|
||||
float r = unitToU12(color.r);
|
||||
float g = unitToU12(color.g);
|
||||
float b = unitToU12(color.b);
|
||||
int u = u12Row(r, g, b, -0.16245023906230927, -0.5464943051338196, 0.7089447379112244);
|
||||
int v = u12Row(r, g, b, 0.9999967217445374, -0.9083024859428406, -0.09169333428144455);
|
||||
int red = clamp(sharp + ((3225 * v + 2048) >> 12), 0, 4095);
|
||||
int green = clamp(sharp + ((-959 * v + -541 * u + 2048) >> 12), 0, 4095);
|
||||
int blue = clamp(sharp + ((5360 * u + 2048) >> 12), 0, 4095);
|
||||
oColor = vec4(u12ToUnit(red), u12ToUnit(green), u12ToUnit(blue), 1.0);
|
||||
}
|
||||
""".trimIndent()
|
||||
|
||||
val lumaShader = join(header, floatOps, luma)
|
||||
val level1Shader = join(header, integerOps, level1)
|
||||
val level2Shader = join(header, integerOps, level2)
|
||||
val outputShader = join(header, integerOps, floatOps, output)
|
||||
|
||||
private fun join(vararg parts: String) = parts.joinToString("\n\n")
|
||||
}
|
||||
@@ -2,14 +2,12 @@ package com.hinnka.mycamera.raw
|
||||
|
||||
import com.hinnka.mycamera.processor.PhotonCoreImagingTuning
|
||||
import com.hinnka.mycamera.processor.PhotonSharpenTuning
|
||||
import com.hinnka.mycamera.utils.LargeDirectBuffer
|
||||
import java.nio.ByteBuffer
|
||||
|
||||
/** Original MGC AOT kernels, retaining float RGB until their U12 boundary. */
|
||||
/** MGC FinishRaw sharpening: the GLES SharpenTo16Bit port, or GuidedUpsample when prepared. */
|
||||
internal class MgcSharpen {
|
||||
private val transfer = RawFloatTextureTransfer()
|
||||
val guided = MgcGuidedUpsample(transfer)
|
||||
private var scratch: ByteBuffer? = null
|
||||
private val sharpen = GlesMgcSharpen()
|
||||
|
||||
fun render(sourceTexture: Int, targetTexture: Int, width: Int, height: Int,
|
||||
snr: Float, attenuation: Float,
|
||||
@@ -21,37 +19,18 @@ internal class MgcSharpen {
|
||||
guided.render(sourceTexture, targetTexture, width, height, attenuation, curves.points)
|
||||
return
|
||||
}
|
||||
val pixels = width.toLong() * height
|
||||
val outputPixels = width.toLong() * ((height.toLong() + 1) and -2L)
|
||||
val scratchBytes = (pixels + outputPixels) * 6
|
||||
require(scratchBytes <= Int.MAX_VALUE)
|
||||
if ((scratch?.capacity()?.toLong() ?: 0) < scratchBytes) {
|
||||
LargeDirectBuffer.free(scratch)
|
||||
scratch = null
|
||||
scratch = checkNotNull(LargeDirectBuffer.allocate(scratchBytes, "MGC sharpen YUV/RGB"))
|
||||
}
|
||||
transfer.read(sourceTexture, width, height, label = "sharpen") { mapped ->
|
||||
val result = nativeSharpenRgbaFloat(mapped, checkNotNull(scratch), width, height,
|
||||
snr, attenuation, curves.points)
|
||||
check(result == 0) { "MGC original sharpen failed: $result" }
|
||||
}
|
||||
transfer.upload(targetTexture, width, height)
|
||||
sharpen.render(sourceTexture, targetTexture, width, height, curves.points, attenuation)
|
||||
}
|
||||
|
||||
fun releaseBuffers() {
|
||||
guided.release()
|
||||
LargeDirectBuffer.free(scratch)
|
||||
scratch = null
|
||||
sharpen.releaseBuffers()
|
||||
transfer.releaseBuffers()
|
||||
}
|
||||
|
||||
fun release() {
|
||||
releaseBuffers()
|
||||
sharpen.release()
|
||||
transfer.release()
|
||||
}
|
||||
|
||||
private external fun nativeSharpenRgbaFloat(rgba: ByteBuffer, scratch: ByteBuffer,
|
||||
width: Int, height: Int, snr: Float, attenuation: Float, curves: FloatArray): Int
|
||||
|
||||
companion object { init { System.loadLibrary("my-native-lib") } }
|
||||
}
|
||||
@@ -1,329 +0,0 @@
|
||||
// Standalone Android/arm64 probe. No APK or instrumentation test installation.
|
||||
// Compile with the production MGC adapter/runtime/capsule, -fopenmp
|
||||
// -static-openmp -fno-fast-math -ffp-contract=off -ffunction-sections
|
||||
// -Wl,--gc-sections.
|
||||
#include "mgc_denoise_static.h"
|
||||
#include "mgc_sharpen_adapter.h"
|
||||
#include <EGL/egl.h>
|
||||
#include <GLES3/gl31.h>
|
||||
#include <algorithm>
|
||||
#include <chrono>
|
||||
#include <cmath>
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
#include <fstream>
|
||||
#include <iterator>
|
||||
#include <jni.h>
|
||||
#include <vector>
|
||||
using namespace photon::mgc_denoise;
|
||||
using Clock = std::chrono::steady_clock;
|
||||
extern "C" jfloat
|
||||
Java_com_hinnka_mycamera_raw_RawDemosaicProcessor_estimateMgcReferenceSignalNative(
|
||||
JNIEnv *, jobject, jobject, jint, jint, jint, jint, jint, jint, jint,
|
||||
jfloat, jint, jfloat);
|
||||
|
||||
// Only the two direct-buffer JNI functions used by the production statistics
|
||||
// entry are stubbed. All validation, sampling, histogram coordinates, sqrt and
|
||||
// reduction run in production code.
|
||||
static void SignalStats(int w, int h) {
|
||||
struct Buffer {
|
||||
void *data;
|
||||
jlong bytes;
|
||||
};
|
||||
std::vector<uint16_t> raw(size_t(w) * h, 512);
|
||||
Buffer buffer{raw.data(), jlong(raw.size() * 2)};
|
||||
JNINativeInterface functions{};
|
||||
functions.GetDirectBufferAddress = [](JNIEnv *, jobject b) -> void * {
|
||||
return reinterpret_cast<Buffer *>(b)->data;
|
||||
};
|
||||
functions.GetDirectBufferCapacity = [](JNIEnv *, jobject b) -> jlong {
|
||||
return reinterpret_cast<Buffer *>(b)->bytes;
|
||||
};
|
||||
JNIEnv env{&functions};
|
||||
for (int i = 0; i < 4; ++i) {
|
||||
auto start = Clock::now();
|
||||
float signal =
|
||||
Java_com_hinnka_mycamera_raw_RawDemosaicProcessor_estimateMgcReferenceSignalNative(
|
||||
&env, nullptr, reinterpret_cast<jobject>(&buffer), 0, buffer.bytes,
|
||||
w, h, w * 2, 1, 1, 64.f, 4095, 4031.f);
|
||||
double ms =
|
||||
std::chrono::duration<double, std::milli>(Clock::now() - start).count();
|
||||
if (!std::isfinite(signal) || std::abs(signal - 448.f / 4031.f) > 1e-6f)
|
||||
std::exit(1);
|
||||
printf("signalStats %dx%d run=%d nativeMs=%.3f signal=%.9g\n", w, h, i, ms,
|
||||
signal);
|
||||
}
|
||||
}
|
||||
static void Check(bool ok, const char *what) {
|
||||
if (!ok) {
|
||||
fprintf(stderr, "FAIL %s gl=%x\n", what, glGetError());
|
||||
std::exit(1);
|
||||
}
|
||||
}
|
||||
static double Ms(Clock::time_point t) {
|
||||
return std::chrono::duration<double, std::milli>(Clock::now() - t).count();
|
||||
}
|
||||
static void Scalar(const uint8_t *rgba, size_t n, int16_t *out) {
|
||||
constexpr float m[] = {
|
||||
.2125999927520752f, .7152000069618225f, .07219959795475006f,
|
||||
-.16245023906230927f, -.5464943051338196f, .7089447379112244f,
|
||||
.9999967217445374f, -.9083024859428406f, -.09169333428144455f};
|
||||
#pragma omp parallel for schedule(static) num_threads(4)
|
||||
for (size_t i = 0; i < n; i++) {
|
||||
float r = rgba[i * 4] * (4095.f / 255.f),
|
||||
g = rgba[i * 4 + 1] * (4095.f / 255.f),
|
||||
b = rgba[i * 4 + 2] * (4095.f / 255.f);
|
||||
for (int c = 0; c < 3; c++)
|
||||
out[c * n + i] = std::clamp<long>(
|
||||
std::lrintf(m[c * 3] * r + m[c * 3 + 1] * g + m[c * 3 + 2] * b),
|
||||
-4095, 4095);
|
||||
}
|
||||
}
|
||||
static void VerifyConversions() {
|
||||
constexpr size_t n = 65536;
|
||||
std::vector<uint8_t> rgba(n * 4);
|
||||
std::vector<int16_t> a(n * 3), b(n * 3);
|
||||
for (int r = 0; r < 256; r++) {
|
||||
for (size_t i = 0; i < n; i++) {
|
||||
rgba[i * 4] = r;
|
||||
rgba[i * 4 + 1] = i / 256;
|
||||
rgba[i * 4 + 2] = i % 256;
|
||||
rgba[i * 4 + 3] = 255;
|
||||
}
|
||||
Scalar(rgba.data(), n, a.data());
|
||||
SharpenRgbaToYuv(rgba.data(), n, b.data());
|
||||
Check(a == b, "all RGB8 -> YUV12 exact");
|
||||
}
|
||||
for (size_t tail = 1; tail < 24; tail++) {
|
||||
Scalar(rgba.data(), tail, a.data());
|
||||
SharpenRgbaToYuv(rgba.data(), tail, b.data());
|
||||
Check(std::equal(a.begin(), a.begin() + tail * 3, b.begin()),
|
||||
"NEON scalar tail");
|
||||
}
|
||||
std::vector<uint16_t> rgb(n * 3);
|
||||
for (size_t i = 0; i < rgb.size(); i++)
|
||||
rgb[i] = i % 65536;
|
||||
SharpenRgbToRgba(rgb.data(), n, rgba.data());
|
||||
for (size_t i = 0; i < n; i++)
|
||||
for (int c = 0; c < 3; c++)
|
||||
Check(rgba[i * 4 + c] ==
|
||||
(std::min<unsigned>(rgb[i * 3 + c], 4095) * 255 + 2047) / 4095,
|
||||
"U12 to U8 exact");
|
||||
puts("PASS all 16777216 RGB8 colors, SIMD tails, all uint16 output values");
|
||||
}
|
||||
static void Sharpen(int16_t *in, uint16_t *out, int w, int h) {
|
||||
// Frozen SNR20 generic fixture for adapter/tile/performance checks.
|
||||
// Production defaults now live only in PhotonSharpenTuning; the JVM regression
|
||||
// checks cover its table and SNR interpolation independently of this probe.
|
||||
const float curves[] = {
|
||||
0, .05f, 1, 2, 3, 0, .03f, 1, 2, 3, 0, .02f, 1, 2, 3,
|
||||
0, .05f * 1.6f, 3.2f, 2, 3,
|
||||
0, .03f * 1.3f, 2.6f, 2, 3,
|
||||
0, .02f, 1.4f, 2, 3,
|
||||
};
|
||||
const float corner_correction[] = {0, 0, 0};
|
||||
int rc =
|
||||
RunSharpenTo16Bit(in, w, h, curves, corner_correction, .8f, out);
|
||||
if (rc)
|
||||
fprintf(stderr, "kernel size=%dx%d rc=%d\n", w, h, rc);
|
||||
Check(rc == 0, "kernel");
|
||||
}
|
||||
static void VerifyTiles() {
|
||||
const int w = 512, h = 384;
|
||||
const size_t n = w * h;
|
||||
std::vector<uint8_t> rgba(n * 4);
|
||||
for (size_t i = 0; i < rgba.size(); i++)
|
||||
rgba[i] = (i * 17 + i / 31) % 256;
|
||||
std::vector<int16_t> in(n * 3);
|
||||
std::vector<uint16_t> full(n * 3);
|
||||
SharpenRgbaToYuv(rgba.data(), n, in.data());
|
||||
Sharpen(in.data(), full.data(), w, h);
|
||||
// CFA-only phase 2 and odd dimensions are deliberate; the kernel must not
|
||||
// reset a pyramid phase.
|
||||
for (int origin : {0, 2, 8, 16, 50, 112}) {
|
||||
const int tw = 257, th = 193;
|
||||
const size_t tn = tw * th;
|
||||
std::vector<int16_t> ti(tn * 3);
|
||||
std::vector<uint16_t> to(size_t(tw) * ((th + 1) & ~1) * 3);
|
||||
for (int c = 0; c < 3; c++)
|
||||
for (int y = 0; y < th; y++)
|
||||
std::copy_n(in.data() + c * n + (y + origin) * w + origin, tw,
|
||||
ti.data() + c * tn + y * tw);
|
||||
Sharpen(ti.data(), to.data(), tw, th);
|
||||
size_t mismatches = 0;
|
||||
for (int y = 52; y < th - 52; y++)
|
||||
for (int x = 52; x < tw - 52; x++)
|
||||
for (int c = 0; c < 3; c++)
|
||||
mismatches += to[(y * tw + x) * 3 + c] !=
|
||||
full[((y + origin) * w + x + origin) * 3 + c];
|
||||
printf("tile origin=%d mismatches=%zu\n", origin, mismatches);
|
||||
Check(mismatches == 0,
|
||||
"tile interior equivalence with 52px sharpen support");
|
||||
}
|
||||
}
|
||||
static void Gpu(int w, int h, const char *shaderFile) {
|
||||
EGLDisplay d = eglGetDisplay(EGL_DEFAULT_DISPLAY);
|
||||
Check(eglInitialize(d, nullptr, nullptr), "eglInitialize");
|
||||
EGLint attrs[] = {EGL_SURFACE_TYPE, EGL_PBUFFER_BIT, EGL_RENDERABLE_TYPE,
|
||||
EGL_OPENGL_ES3_BIT, EGL_NONE},
|
||||
num = 0;
|
||||
EGLConfig cfg;
|
||||
Check(eglChooseConfig(d, attrs, &cfg, 1, &num) && num > 0, "eglChooseConfig");
|
||||
EGLint ca[] = {EGL_CONTEXT_CLIENT_VERSION, 3, EGL_NONE},
|
||||
pa[] = {EGL_WIDTH, 1, EGL_HEIGHT, 1, EGL_NONE};
|
||||
EGLContext ctx = eglCreateContext(d, cfg, EGL_NO_CONTEXT, ca);
|
||||
EGLSurface surf = eglCreatePbufferSurface(d, cfg, pa);
|
||||
Check(eglMakeCurrent(d, surf, surf, ctx), "eglMakeCurrent");
|
||||
printf("GPU %s %s\n", glGetString(GL_RENDERER), glGetString(GL_VERSION));
|
||||
std::ifstream f(shaderFile);
|
||||
std::string src((std::istreambuf_iterator<char>(f)), {});
|
||||
Check(!src.empty(), "shader source");
|
||||
GLuint sh = glCreateShader(GL_COMPUTE_SHADER);
|
||||
const char *p = src.c_str();
|
||||
glShaderSource(sh, 1, &p, nullptr);
|
||||
glCompileShader(sh);
|
||||
GLint ok;
|
||||
glGetShaderiv(sh, GL_COMPILE_STATUS, &ok);
|
||||
if (!ok) {
|
||||
char log[2048];
|
||||
glGetShaderInfoLog(sh, 2048, nullptr, log);
|
||||
puts(log);
|
||||
}
|
||||
Check(ok, "compute compile");
|
||||
GLuint prog = glCreateProgram();
|
||||
glAttachShader(prog, sh);
|
||||
glLinkProgram(prog);
|
||||
glGetProgramiv(prog, GL_LINK_STATUS, &ok);
|
||||
Check(ok, "compute link");
|
||||
size_t n = size_t(w) * h, bytes = n * 4;
|
||||
std::vector<uint8_t> input(bytes), reference(bytes), result(bytes);
|
||||
for (size_t i = 0; i < n; i++) {
|
||||
input[i * 4] = (i * 13 + i / w) % 256;
|
||||
input[i * 4 + 1] = (i * 19) % 256;
|
||||
input[i * 4 + 2] = (i / 7) % 256;
|
||||
input[i * 4 + 3] = 255;
|
||||
}
|
||||
std::vector<int16_t> yuv(n * 3);
|
||||
std::vector<uint16_t> rgb(size_t(w) * ((h + 1) & ~1) * 3);
|
||||
auto t = Clock::now();
|
||||
Scalar(input.data(), n, yuv.data());
|
||||
double oldMs = Ms(t);
|
||||
t = Clock::now();
|
||||
SharpenRgbaToYuv(input.data(), n, yuv.data());
|
||||
double newMs = Ms(t);
|
||||
t = Clock::now();
|
||||
Sharpen(yuv.data(), rgb.data(), w, h);
|
||||
double kernelMs = Ms(t);
|
||||
t = Clock::now();
|
||||
SharpenRgbToRgba(rgb.data(), n, reference.data());
|
||||
double outputMs = Ms(t);
|
||||
printf("CPU %dx%d oldConvertMs=%.3f neonConvertMs=%.3f kernelMs=%.3f "
|
||||
"outMs=%.3f\n",
|
||||
w, h, oldMs, newMs, kernelMs, outputMs);
|
||||
GLuint tex[2], fb, buf;
|
||||
glGenTextures(2, tex);
|
||||
for (auto v : tex) {
|
||||
glBindTexture(GL_TEXTURE_2D, v);
|
||||
glTexStorage2D(GL_TEXTURE_2D, 1, GL_RGBA8, w, h);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
||||
}
|
||||
glBindTexture(GL_TEXTURE_2D, tex[0]);
|
||||
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, w, h, GL_RGBA, GL_UNSIGNED_BYTE,
|
||||
input.data());
|
||||
glGenFramebuffers(1, &fb);
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, fb);
|
||||
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D,
|
||||
tex[0], 0);
|
||||
Check(glCheckFramebufferStatus(GL_FRAMEBUFFER) == GL_FRAMEBUFFER_COMPLETE,
|
||||
"framebuffer");
|
||||
glGenBuffers(1, &buf);
|
||||
glBindBuffer(GL_PIXEL_PACK_BUFFER, buf);
|
||||
glBufferData(GL_PIXEL_PACK_BUFFER, bytes, nullptr, GL_STREAM_COPY);
|
||||
GLint64 limit;
|
||||
glGetInteger64v(GL_MAX_SHADER_STORAGE_BLOCK_SIZE, &limit);
|
||||
Check(bytes <= size_t(limit), "SSBO limit");
|
||||
for (bool compute : {false, true})
|
||||
for (int run = 0; run < 3; run++) {
|
||||
glFinish();
|
||||
t = Clock::now();
|
||||
if (compute) {
|
||||
glUseProgram(prog);
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
glBindTexture(GL_TEXTURE_2D, tex[0]);
|
||||
glUniform1i(glGetUniformLocation(prog, "uInput"), 0);
|
||||
glUniform2i(glGetUniformLocation(prog, "uSize"), w, h);
|
||||
glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 0, buf);
|
||||
glDispatchCompute((w + 7) / 8, (h + 7) / 8, 1);
|
||||
glMemoryBarrier(GL_SHADER_STORAGE_BARRIER_BIT |
|
||||
GL_BUFFER_UPDATE_BARRIER_BIT);
|
||||
glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 0, 0);
|
||||
} else {
|
||||
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
|
||||
GL_TEXTURE_2D, tex[0], 0);
|
||||
glBindBuffer(GL_PIXEL_PACK_BUFFER, buf);
|
||||
glReadPixels(0, 0, w, h, GL_RGBA, GL_UNSIGNED_BYTE, 0);
|
||||
}
|
||||
glBindBuffer(GL_PIXEL_PACK_BUFFER, buf);
|
||||
auto *mapped = (uint8_t *)glMapBufferRange(
|
||||
GL_PIXEL_PACK_BUFFER, 0, bytes, GL_MAP_READ_BIT | GL_MAP_WRITE_BIT);
|
||||
Check(mapped, "map");
|
||||
double transfer = Ms(t);
|
||||
Check(memcmp(mapped, input.data(), bytes) == 0,
|
||||
"packed RGBA8 equals framebuffer input");
|
||||
t = Clock::now();
|
||||
SharpenRgbaToYuv(mapped, n, yuv.data());
|
||||
double cin = Ms(t);
|
||||
t = Clock::now();
|
||||
Sharpen(yuv.data(), rgb.data(), w, h);
|
||||
double kernel = Ms(t);
|
||||
t = Clock::now();
|
||||
SharpenRgbToRgba(rgb.data(), n, mapped);
|
||||
double cout = Ms(t);
|
||||
Check(glUnmapBuffer(GL_PIXEL_PACK_BUFFER), "unmap");
|
||||
glBindBuffer(GL_PIXEL_PACK_BUFFER, 0);
|
||||
t = Clock::now();
|
||||
glBindBuffer(GL_PIXEL_UNPACK_BUFFER, buf);
|
||||
glBindTexture(GL_TEXTURE_2D, tex[1]);
|
||||
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, w, h, GL_RGBA, GL_UNSIGNED_BYTE,
|
||||
nullptr);
|
||||
glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0);
|
||||
glFinish();
|
||||
double upload = Ms(t);
|
||||
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
|
||||
GL_TEXTURE_2D, tex[1], 0);
|
||||
glReadPixels(0, 0, w, h, GL_RGBA, GL_UNSIGNED_BYTE, result.data());
|
||||
Check(result == reference, "full original kernel transfer output exact");
|
||||
Check(glGetError() == GL_NO_ERROR, "complete GL chain");
|
||||
printf("GPU %dx%d %s run=%d transferMapMs=%.3f convertInMs=%.3f "
|
||||
"kernelMs=%.3f convertOutMs=%.3f uploadGpuCompleteMs=%.3f "
|
||||
"sumMs=%.3f exact=true\n",
|
||||
w, h, compute ? "SSBO" : "PBO", run, transfer, cin, kernel, cout,
|
||||
upload, transfer + cin + kernel + cout + upload);
|
||||
fflush(stdout);
|
||||
}
|
||||
glDeleteBuffers(1, &buf);
|
||||
glDeleteTextures(2, tex);
|
||||
glDeleteFramebuffers(1, &fb);
|
||||
glDeleteProgram(prog);
|
||||
glDeleteShader(sh);
|
||||
eglMakeCurrent(d, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
|
||||
eglDestroySurface(d, surf);
|
||||
eglDestroyContext(d, ctx);
|
||||
eglTerminate(d);
|
||||
}
|
||||
int main(int argc, char **argv) {
|
||||
if (argc == 2 && std::strcmp(argv[1], "--stats") == 0) {
|
||||
SignalStats(4000, 3000);
|
||||
SignalStats(8192, 6144);
|
||||
return 0;
|
||||
}
|
||||
if (argc == 1) {
|
||||
VerifyConversions();
|
||||
VerifyTiles();
|
||||
return 0;
|
||||
}
|
||||
Check(argc == 4, "arguments width height shaderFile");
|
||||
Gpu(atoi(argv[1]), atoi(argv[2]), argv[3]);
|
||||
}
|
||||
Reference in new issue
Block a user