perf: defer unused GPU work and streamline preview rendering

这个提交包含在:
mac 于 2026-11-08 16:10:13 +08:00 提交
1 父节点 c9e4d3f330
当前提交 ccc34734e3
18 个文件已更改
+362 -115

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

+25 -8
查看文件
@@ -232,16 +232,30 @@ fragment half4 dySegmentFragment(DYRaster in [[stage_in]],
// Optional boundary conversion. Use this before both statistics and grading
// when the host supplies premultiplied RGB; all neighborhood samples then see
// the same straight RGB representation. Source and destination must differ.
inline half4 dyStraightSample(float4 sample) {
if (!(sample.a > 0.0f) || !all(isfinite(sample))) return half4(0.0h);
return half4(half3(sample.rgb / sample.a), half(sample.a));
}
kernel void dyUnpremultiply(texture2d<float, access::read> source [[texture(0)]],
texture2d<half, access::write> destination [[texture(1)]],
uint2 pixel [[thread_position_in_grid]]) {
if (pixel.x >= destination.get_width() || pixel.y >= destination.get_height()) return;
float4 sample = source.read(pixel);
if (!(sample.a > 0.0f) || !all(isfinite(sample))) {
destination.write(half4(0.0h), pixel);
return;
}
destination.write(half4(half3(sample.rgb / sample.a), half(sample.a)), pixel);
destination.write(dyStraightSample(source.read(pixel)), pixel);
}
// Match the historical half-precision alpha round trip without an intermediate
// texture when source and destination cover the same pixel grid.
fragment half4 dyNeutralInputFragment(DYRaster in [[stage_in]],texture2d<float,access::read> source [[texture(0)]]) {
uint2 size(source.get_width(),source.get_height());
half4 c=dyStraightSample(source.read(min(uint2(in.uv*float2(size)),size-1)));
return c.a>0.0h?half4(c.rgb*c.a,c.a):half4(0.0h);
}
fragment half4 dyNeutralOutputFragment(DYRaster in [[stage_in]],texture2d<half> source [[texture(0)]]) {
constexpr sampler f(coord::normalized,address::clamp_to_edge,filter::linear);
half4 c=source.sample(f,in.uv);
return c.a>0.0h?half4(c.rgb*c.a,c.a):half4(0.0h);
}
// Per-instance CPU analysis thumbnail. Host dispatches exactly 64x64 threads;
@@ -314,9 +328,12 @@ inline float3 dyDecode(float3 encoded) {
}
kernel void dyColorManagement(texture2d<float,access::read> source [[texture(0)]],
texture2d<half,access::write> destination [[texture(1)]],
constant DayuRenderParams& p [[buffer(0)]],constant float& amount [[buffer(1)]],uint2 pos [[thread_position_in_grid]]) {
constant DayuRenderParams& p [[buffer(0)]],constant float& amount [[buffer(1)]],
constant uint& premultiplied [[buffer(2)]],uint2 pos [[thread_position_in_grid]]) {
if(pos.x>=source.get_width()||pos.y>=source.get_height())return;
float4 sample=source.read(pos);if(!(sample.a>0)){destination.write(half4(0),pos);return;}
float4 sample=source.read(pos);
if(premultiplied)sample=float4(dyStraightSample(sample));
if(!(sample.a>0)){destination.write(half4(0),pos);return;}
float4 raw=float4(dyEncode(sample.rgb),sample.a),c=raw;
if(p.stages&1)c=cst_air(half4(c),p.input);
if(p.stages&2){if(p.reserved&8)c=cst_air(half4(c),p.basisInput);c=basis_air(half4(c),p.basis);if(p.reserved&8)c=cst_air(half4(c),p.basisOutput);}