Files
NX2navi/runtime/shaders/fallback_tonemap.spvasm
chrg6 77d0c0b84e Port Ocarina of Time (Switch 2) to the recomp host
The NVN2 front end and the SM86 to Maxwell shader lowering (tools/xlate/AmpereLowering.cs, mesh and task stages,
bindless texture pools, BRX jump tables, the NVN2 compute c0 layout) with four translator patches (0017-0020) bring the
opening of the game to 58-60 fps on the Vulkan renderer.

This round fixes the haze: SM86 IPA is lowered as a plain Maxwell IPA.PASS (texture coordinates were corrected for
perspective twice); LDSM, TXD, both F2IP byte forms, HMMA, MOVM and HFMA2.RELU are lowered and spill mode has eight
uniform register groups; conditional rendering keeps the newest counter report per address and treats a report as
pending until its value is in guest memory, so occlusion tests and the depth clears around the depth copy behave; and
the upscaler stand-in decodes the post pass's sRGB picture before writing the linear target. Tensor-core programs keep
the stand-in unless NX2NAVI_NATIVE_TENSOR=1, because their lowering does not match the hardware yet.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-07 05:04:39 -05:00

116 lines
5.4 KiB
Plaintext

; Tonemap and scale for the untranslatable upscaler (runtime/vk_exec_draw.c untranslated_dispatch_fallback).
; Written in SPIR-V assembly (spirv-as; no GLSL compiler in the build). As GLSL:
; layout(local_size_x = 8, local_size_y = 8) in;
; layout(binding = 0) uniform sampler2D src; // the HDR scene (linear filtering)
; layout(binding = 1, rgba16f) uniform writeonly image2D dst; // the pass output (vk_tonemap.c), blitted into the target
; layout(push_constant) uniform P { vec2 inv; float exposure; float pad; ivec2 size; } pc;
; void main() {
; ivec2 p = ivec2(gl_GlobalInvocationID.xy);
; if (p.x >= pc.size.x || p.y >= pc.size.y) return;
; vec3 c = textureLod(src, (vec2(p) + 0.5) * pc.inv, 0.0).rgb * pc.exposure;
; c = clamp(c * (2.51 * c + 0.03) / (c * (2.43 * c + 0.59) + 0.14), 0.0, 1.0); // Narkowicz's ACES fit
; imageStore(dst, p, vec4(c, 1.0));
; }
OpCapability Shader
%1 = OpExtInstImport "GLSL.std.450"
OpMemoryModel Logical GLSL450
OpEntryPoint GLCompute %main "main" %gid %src %dst %pc
OpExecutionMode %main LocalSize 8 8 1
OpDecorate %gid BuiltIn GlobalInvocationId
OpDecorate %src DescriptorSet 0
OpDecorate %src Binding 0
OpDecorate %dst DescriptorSet 0
OpDecorate %dst Binding 1
OpDecorate %dst NonReadable
OpDecorate %P Block
OpMemberDecorate %P 0 Offset 0
OpMemberDecorate %P 1 Offset 8
OpMemberDecorate %P 2 Offset 12
OpMemberDecorate %P 3 Offset 16
%void = OpTypeVoid
%fnvoid = OpTypeFunction %void
%float = OpTypeFloat 32
%int = OpTypeInt 32 1
%uint = OpTypeInt 32 0
%bool = OpTypeBool
%v2float = OpTypeVector %float 2
%v3float = OpTypeVector %float 3
%v4float = OpTypeVector %float 4
%v2int = OpTypeVector %int 2
%v3uint = OpTypeVector %uint 3
%v2uint = OpTypeVector %uint 2
%ptr_in_v3uint = OpTypePointer Input %v3uint
%gid = OpVariable %ptr_in_v3uint Input
%img2d = OpTypeImage %float 2D 0 0 0 1 Unknown
%simg2d = OpTypeSampledImage %img2d
%ptr_uc_simg = OpTypePointer UniformConstant %simg2d
%src = OpVariable %ptr_uc_simg UniformConstant
%stimg = OpTypeImage %float 2D 0 0 0 2 Rgba16f
%ptr_uc_stimg = OpTypePointer UniformConstant %stimg
%dst = OpVariable %ptr_uc_stimg UniformConstant
%P = OpTypeStruct %v2float %float %float %v2int
%ptr_pc_P = OpTypePointer PushConstant %P
%pc = OpVariable %ptr_pc_P PushConstant
%ptr_pc_v2float = OpTypePointer PushConstant %v2float
%ptr_pc_float = OpTypePointer PushConstant %float
%ptr_pc_v2int = OpTypePointer PushConstant %v2int
%int_0 = OpConstant %int 0
%int_1 = OpConstant %int 1
%int_3 = OpConstant %int 3
%float_0 = OpConstant %float 0
%float_1 = OpConstant %float 1
%float_half = OpConstant %float 0.5
%float_2_51 = OpConstant %float 2.51
%float_0_03 = OpConstant %float 0.03
%float_2_43 = OpConstant %float 2.43
%float_0_59 = OpConstant %float 0.59
%float_0_14 = OpConstant %float 0.14
%v2half = OpConstantComposite %v2float %float_half %float_half
%v3_0 = OpConstantComposite %v3float %float_0 %float_0 %float_0
%v3_1 = OpConstantComposite %v3float %float_1 %float_1 %float_1
%v3_2_51 = OpConstantComposite %v3float %float_2_51 %float_2_51 %float_2_51
%v3_0_03 = OpConstantComposite %v3float %float_0_03 %float_0_03 %float_0_03
%v3_2_43 = OpConstantComposite %v3float %float_2_43 %float_2_43 %float_2_43
%v3_0_59 = OpConstantComposite %v3float %float_0_59 %float_0_59 %float_0_59
%v3_0_14 = OpConstantComposite %v3float %float_0_14 %float_0_14 %float_0_14
%v2bool = OpTypeVector %bool 2
%main = OpFunction %void None %fnvoid
%entry = OpLabel
%g3 = OpLoad %v3uint %gid
%gu = OpVectorShuffle %v2uint %g3 %g3 0 1
%p = OpBitcast %v2int %gu
%psize = OpAccessChain %ptr_pc_v2int %pc %int_3
%size = OpLoad %v2int %psize
%ge = OpSGreaterThanEqual %v2bool %p %size
%out = OpAny %bool %ge
OpSelectionMerge %body None
OpBranchConditional %out %done %body
%done = OpLabel
OpReturn
%body = OpLabel
%pf = OpConvertSToF %v2float %p
%pfh = OpFAdd %v2float %pf %v2half
%pinv = OpAccessChain %ptr_pc_v2float %pc %int_0
%inv = OpLoad %v2float %pinv
%uv = OpFMul %v2float %pfh %inv
%si = OpLoad %simg2d %src
%s4 = OpImageSampleExplicitLod %v4float %si %uv Lod %float_0
%s3 = OpVectorShuffle %v3float %s4 %s4 0 1 2
%pexp = OpAccessChain %ptr_pc_float %pc %int_1
%exp = OpLoad %float %pexp
%c = OpVectorTimesScalar %v3float %s3 %exp
%a1 = OpFMul %v3float %c %v3_2_51
%a2 = OpFAdd %v3float %a1 %v3_0_03
%num = OpFMul %v3float %c %a2
%b1 = OpFMul %v3float %c %v3_2_43
%b2 = OpFAdd %v3float %b1 %v3_0_59
%b3 = OpFMul %v3float %c %b2
%den = OpFAdd %v3float %b3 %v3_0_14
%t = OpFDiv %v3float %num %den
%tc = OpExtInst %v3float %1 FClamp %t %v3_0 %v3_1
%o4 = OpCompositeConstruct %v4float %tc %float_1
%di = OpLoad %stimg %dst
OpImageWrite %di %p %o4
OpReturn
OpFunctionEnd