R"(

#ifdef _DISABLE_EARLY_DISCARD
	if (_fragment_discard)
	{
		discard;
	}
#endif

#ifdef _ENABLE_FRAMEBUFFER_SRGB
	col0.rgb = _mrt_color_t(linear_to_srgb(col0)).rgb;
	col1.rgb = _mrt_color_t(linear_to_srgb(col1)).rgb;
	col2.rgb = _mrt_color_t(linear_to_srgb(col2)).rgb;
	col3.rgb = _mrt_color_t(linear_to_srgb(col3)).rgb;
#endif

#ifdef _ENABLE_ROP_OUTPUT_ROUNDING
	col0 = round_to_8bit(col0);
	col1 = round_to_8bit(col1);
	col2 = round_to_8bit(col2);
	col3 = round_to_8bit(col3);
#endif

	// Post-output stages
	// Alpha Testing
#ifdef _ENABLE_ALPHA_TEST
	const uint alpha_func = _get_bits(rop_control, ALPHA_TEST_FUNC_OFFSET, ALPHA_TEST_FUNC_LENGTH);
	if (!comparison_passes(col0.a, alpha_ref, alpha_func))
	{
		discard;
	}
#endif

#ifdef _ENABLE_ALPHA_TO_COVERAGE_TEST
	if (!coverage_test_passes(col0))
	{
		discard;
	}
#endif

#ifdef _ENABLE_DEPTH_COMPARE
#ifdef _ENABLE_DEPTH_BUFFER_MULTISAMPLED
	float dstDepth = texelFetch(frag_depth, ivec2(gl_FragCoord.xy), gl_SampleID).r;
#else
	float dstDepth = texelFetch(frag_depth, ivec2(gl_FragCoord.xy), 0).r;
#endif
	float srcDepth = gl_FragCoord.z;
	float scale = _test_bit(rop_control, FRAG_DEPTH_24_BIT) ? float(0xffffffu) : float(0xffffu);

	// Quantize and compare
	if (abs(srcDepth - dstDepth) < (1.f / scale))
	{
		gl_FragDepth = dstDepth;
	}
	else
	{
		gl_FragDepth = srcDepth;
	}
#endif

#ifdef _ENABLE_PROGRAMMABLE_BLENDING
	switch (framebufferCount)
	{
		case 4:
			col3 = do_blend(col3, mrt_color[3]);
			// Fallthrough
		case 3:
			col2 = do_blend(col2, mrt_color[2]);
			// Fallthrough
		case 2:
			col1 = do_blend(col1, mrt_color[1]);
			// Fallthrough
		default:
			col0 = do_blend(col0, mrt_color[0]);
			break;
	}
#endif

	// Commit
	ocol0 = col0;
	ocol1 = col1;
	ocol2 = col2;
	ocol3 = col3;
)"
