Skip to content

Commit 9d61b0e

Browse files
Spruill-1Copilot
andcommitted
Migrate ICtCp Inverse Tone Map to D3D11 compute
Pilot for the compute-migration cohort. ICtCp Tone Map (HDR -> SDR) was already migrated in the original Phase 8 work; the symmetric inverse mapping is the natural first follow-on: * Same shape as the migrated forward tone map -- t0 source / u1 image output / shaderlab_params macros for SourcePeakNits + TargetPeakNits. * Both peak parameters marked gpuBindable=true so an upstream Luminance Statistics .Max can route directly into the consumer SRV with no CPU readback round-trip on the bound binding (the Phase 8c skip-readback win). * effectVersion bumped 10 -> 11. * Verified on HDR Test Pattern at SourcePeak=203, TargetPeak=4000: output expands SDR-anchored content past 1.0 in scRGB linear (clipped in the sRGB-byte PNG capture) -- expected behavior. 154/154 tests pass. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 8d0e12c commit 9d61b0e

1 file changed

Lines changed: 34 additions & 17 deletions

File tree

Effects/ShaderLabEffects.cpp

Lines changed: 34 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2224,49 +2224,66 @@ void main(uint3 dtid : SV_DispatchThreadID)
22242224
// ---- ICtCp Inverse Tone Map (SDR -> HDR) ----
22252225
// Inverse Reinhard on I; expands SDR-anchored content into the
22262226
// HDR peak. Mirror of ICtCp Tone Map; Ct/Cp unchanged.
2227+
// D3D11 compute -- SourcePeakNits + TargetPeakNits gpuBindable.
22272228
{
22282229
static const std::string ictcpInverseToneMapHLSL = R"HLSL(
2229-
// ICtCp Inverse Tone Map (SDR -> HDR), I-channel inverse Reinhard
2230-
Texture2D Source : register(t0);
2231-
SamplerState Sampler : register(s0);
2230+
// ICtCp Inverse Tone Map (SDR -> HDR) -- D3D11 compute, I-channel inverse Reinhard.
2231+
#include "shaderlab_params.hlsli"
2232+
2233+
Texture2D<float4> Source : register(t0);
2234+
RWTexture2D<float4> ImageOutput : register(u1);
2235+
2236+
SHADERLAB_GPU_BUFFER(SourcePeakNits, t1)
2237+
SHADERLAB_GPU_BUFFER(TargetPeakNits, t2)
22322238
22332239
cbuffer constants : register(b0) {
2234-
float SourcePeakNits; // SDR source peak (e.g. 80, 203)
2235-
float TargetPeakNits; // typical 1000-10000
2236-
float Strength; // 0..1 lerp from identity to expanded
2240+
uint Width;
2241+
uint Height;
2242+
SHADERLAB_PARAM(float, SourcePeakNits) // SDR source peak (e.g. 80, 203)
2243+
SHADERLAB_PARAM(float, TargetPeakNits) // typical 1000-10000
2244+
float Strength; // 0..1 lerp from identity to expanded
22372245
};
22382246
2239-
float4 main(float4 pos : SV_POSITION, float2 uv : TEXCOORD) : SV_Target
2247+
[numthreads(8, 8, 1)]
2248+
void main(uint3 dtid : SV_DispatchThreadID)
22402249
{
2241-
float4 color = Source.Load(int3(uv, 0));
2250+
if (dtid.x >= Width || dtid.y >= Height) return;
2251+
2252+
SHADERLAB_LOAD_PARAM(float, SourcePeakNits)
2253+
SHADERLAB_LOAD_PARAM(float, TargetPeakNits)
2254+
2255+
float4 color = Source.Load(int3(dtid.xy, 0));
22422256
float3 ictcp = ScRGBToICtCp(color.rgb);
22432257
22442258
// Inverse of ReinhardCompressI(x, peakIn=HDR, peakOut=SDR):
22452259
// for SDR -> HDR expansion we feed the *compressed* (SDR) range as
2246-
// peakOut and the *expanded* (HDR) range as peakIn. The input I lives
2247-
// in [0, peakOut_I] (SDR range) and the helper returns an I in
2248-
// [0, peakIn_I] (HDR range).
2260+
// peakOut and the *expanded* (HDR) range as peakIn. Input I lives in
2261+
// [0, sdrI] (SDR range); the helper returns I in [0, hdrI] (HDR).
22492262
float sdrI = NitsToI(SourcePeakNits);
22502263
float hdrI = NitsToI(TargetPeakNits);
22512264
float expanded = ReinhardExpandI(ictcp.x, hdrI, sdrI);
22522265
ictcp.x = lerp(ictcp.x, expanded, saturate(Strength));
22532266
22542267
float3 outRgb = ICtCpToScRGB(ictcp);
2255-
return float4(outRgb, color.a);
2268+
ImageOutput[dtid.xy] = float4(outRgb, color.a);
22562269
}
22572270
)HLSL";
22582271
ShaderLabEffectDescriptor desc;
22592272
desc.name = L"ICtCp Inverse Tone Map (SDR -> HDR)";
2260-
desc.effectId = L"ICtCp Inverse Tone Map"; desc.effectVersion = 10;
2273+
desc.effectId = L"ICtCp Inverse Tone Map"; desc.effectVersion = 11;
22612274
desc.category = L"Analysis";
22622275
desc.subcategory = L"Tone Mapping";
2263-
desc.shaderType = Graph::CustomShaderType::PixelShader;
2276+
desc.shaderType = Graph::CustomShaderType::D3D11ComputeShader;
2277+
desc.hasImageOutput = true;
2278+
desc.threadGroupX = 8;
2279+
desc.threadGroupY = 8;
2280+
desc.threadGroupZ = 1;
22642281
desc.hlslSource = colorMath + ictcpInverseToneMapHLSL;
22652282
desc.inputNames = { L"Source" };
22662283
desc.parameters = {
2267-
{ L"SourcePeakNits", L"float", 203.0f, 80.0f, 500.0f, 1.0f },
2268-
{ L"TargetPeakNits", L"float", 1000.0f, 100.0f, 10000.0f, 50.0f },
2269-
{ L"Strength", L"float", 1.0f, 0.0f, 1.0f, 0.05f },
2284+
Graph::ParameterDefinition{ L"SourcePeakNits", L"float", 203.0f, 80.0f, 500.0f, 1.0f, {}, L"", true },
2285+
Graph::ParameterDefinition{ L"TargetPeakNits", L"float", 1000.0f, 100.0f, 10000.0f, 50.0f, {}, L"", true },
2286+
Graph::ParameterDefinition{ L"Strength", L"float", 1.0f, 0.0f, 1.0f, 0.05f },
22702287
};
22712288
m_effects.push_back(std::move(desc));
22722289
}

0 commit comments

Comments
 (0)