让 Metal 直写 Vision 追踪输入并加入 LUT 高清分屏预览

这个提交包含在:
mac 于 2026-11-08 19:11:01 +08:00 提交
1 父节点 ef0e62419a
当前提交 63c49b0135
22 个文件已更改
+496 -86

没有与搜索条件相匹配的文件

+26 -9
查看文件
@@ -312,21 +312,38 @@ kernel void dyScopeSample(texture2d<float,access::read> source [[texture(0)]],
// Native auto-grade statistics consume the input-converted RGB8 preview.
// Quantization before and after the LUT mirrors the reference NSImage path.
inline float4 dyInputPreviewPixel(texture2d<half> source, texture3d<float> inputLUT,
float inputStrength, float2 uv, bool quantize) {
constexpr sampler f(coord::normalized,address::clamp_to_edge,filter::linear);
half4 sample=source.sample(f,uv);
float3 linear=float3(sample.rgb);
float3 power=1.055f*pow(max(linear,float3(0)),float3(1.0f/2.4f))-.055f;
float3 encoded=clamp(select(power,linear*12.92f,linear<=.0031308f),0.0f,1.0f);
if(quantize)encoded=round(encoded*255.0f)/255.0f;
float strength=clamp(inputStrength,0.0f,1.0f);
if(strength>0.0f){float n=float(inputLUT.get_width());float3 coord=encoded*((n-1.0f)/n)+.5f/n;encoded=mix(encoded,inputLUT.sample(f,coord).rgb,strength);}
encoded=clamp(encoded,0.0f,1.0f);
if(quantize)encoded=round(encoded*255.0f)/255.0f;
return float4(encoded,float(sample.a));
}
kernel void dyInputAnalysis(texture2d<half> source [[texture(0)]],
texture3d<float> inputLUT [[texture(1)]],
device float4* outRGBA [[buffer(0)]],
constant float& inputStrength [[buffer(1)]],
uint2 pixel [[thread_position_in_grid]]) {
if (pixel.x >= 320 || pixel.y >= 180) return;
constexpr sampler f(coord::normalized,address::clamp_to_edge,filter::linear);
half4 sample=source.sample(f,(float2(pixel)+.5f)/float2(320,180));
float3 linear=float3(sample.rgb);
float3 power=1.055f*pow(max(linear,float3(0)),float3(1.0f/2.4f))-.055f;
float3 encoded=round(clamp(select(power,linear*12.92f,linear<=.0031308f),0.0f,1.0f)*255.0f)/255.0f;
float strength=clamp(inputStrength,0.0f,1.0f);
if(strength>0.0f){float n=float(inputLUT.get_width());float3 coord=encoded*((n-1.0f)/n)+.5f/n;encoded=mix(encoded,inputLUT.sample(f,coord).rgb,strength);}
encoded=round(clamp(encoded,0.0f,1.0f)*255.0f)/255.0f;
outRGBA[pixel.y*320+pixel.x]=float4(encoded,float(sample.a));
outRGBA[pixel.y*320+pixel.x]=dyInputPreviewPixel(source,inputLUT,inputStrength,(float2(pixel)+.5f)/float2(320,180),true);
}
#include "DYLookPreview.h"
kernel void dyInputHighPreview(texture2d<half> source [[texture(0)]],
texture3d<float> inputLUT [[texture(1)]], device float4* outRGBA [[buffer(0)]],
constant float& inputStrength [[buffer(1)]],constant uint& flip [[buffer(2)]],
uint2 pixel [[thread_position_in_grid]]) {
constexpr uint2 size(DYLookPreviewHDWidth,DYLookPreviewHDHeight);
if(any(pixel>=size))return;
uint2 sample=uint2(pixel.x,flip?size.y-1-pixel.y:pixel.y);
outRGBA[pixel.y*size.x+pixel.x]=dyInputPreviewPixel(source,inputLUT,inputStrength,(float2(sample)+.5f)/float2(size),false);
}
// CST/BASIS arithmetic is reused verbatim from the versioned dayu-cst source.