void ProgramShaderCache::CreateHeader()
{
	GLSL_VERSION v = g_ogl_config.eSupportedGLSLVersion;
	snprintf(s_glsl_header, sizeof(s_glsl_header),
		"%s\n"
		"%s\n" // ubo
		"%s\n" // early-z
		"%s\n" // 420pack
		"%s\n" // msaa
		"%s\n" // sample shading
		"%s\n" // Sampler binding

		// Precision defines for GLSL ES
		"%s\n"
		"%s\n"

		// Silly differences
		"#define float2 vec2\n"
		"#define float3 vec3\n"
		"#define float4 vec4\n"
		"#define uint2 uvec2\n"
		"#define uint3 uvec3\n"
		"#define uint4 uvec4\n"
		"#define int2 ivec2\n"
		"#define int3 ivec3\n"
		"#define int4 ivec4\n"

		// hlsl to glsl function translation
		"#define frac fract\n"
		"#define lerp mix\n"

		// Terrible hacks, look at DriverDetails.h
		"%s\n" // replace textureSize as constant
		"%s\n" // wipe out all centroid usages

		, GetGLSLVersionString().c_str()
		, v<GLSL_140 ? "#extension GL_ARB_uniform_buffer_object : enable" : ""
		, g_ActiveConfig.backend_info.bSupportsEarlyZ ? "#extension GL_ARB_shader_image_load_store : enable" : ""
		, (g_ActiveConfig.backend_info.bSupportsBindingLayout && v < GLSLES_310) ? "#extension GL_ARB_shading_language_420pack : enable" : ""
		, (g_ogl_config.bSupportsMSAA && v < GLSL_150) ? "#extension GL_ARB_texture_multisample : enable" : ""
		, (g_ogl_config.bSupportSampleShading) ? "#extension GL_ARB_sample_shading : enable" : ""
		, g_ActiveConfig.backend_info.bSupportsBindingLayout ? "#define SAMPLER_BINDING(x) layout(binding = x)" : "#define SAMPLER_BINDING(x)"

		, v>=GLSLES_300 ? "precision highp float;" : ""
		, v>=GLSLES_300 ? "precision highp int;" : ""

		, DriverDetails::HasBug(DriverDetails::BUG_BROKENTEXTURESIZE) ? "#define textureSize(x, y) ivec2(1, 1)" : ""
		, DriverDetails::HasBug(DriverDetails::BUG_BROKENCENTROID) ? "#define centroid" : ""
	);
}
void ProgramShaderCache::CreateHeader()
{
	GLSL_VERSION v = g_ogl_config.eSupportedGLSLVersion;
	bool is_glsles = v >= GLSLES_300;
	std::string SupportedESPointSize;
	std::string SupportedESTextureBuffer;
	switch (g_ogl_config.SupportedESPointSize)
	{
	case 1: SupportedESPointSize = "#extension GL_OES_geometry_point_size : enable"; break;
	case 2: SupportedESPointSize = "#extension GL_EXT_geometry_point_size : enable"; break;
	default: SupportedESPointSize = ""; break;
	}

	switch (g_ogl_config.SupportedESTextureBuffer)
	{
	case ES_TEXBUF_TYPE::TEXBUF_EXT:
		SupportedESTextureBuffer = "#extension GL_EXT_texture_buffer : enable";
	break;
	case ES_TEXBUF_TYPE::TEXBUF_OES:
		SupportedESTextureBuffer = "#extension GL_OES_texture_buffer : enable";
	break;
	case ES_TEXBUF_TYPE::TEXBUF_CORE:
	case ES_TEXBUF_TYPE::TEXBUF_NONE:
		SupportedESTextureBuffer = "";
	break;
	}

	snprintf(s_glsl_header, sizeof(s_glsl_header),
		"%s\n"
		"%s\n" // ubo
		"%s\n" // early-z
		"%s\n" // 420pack
		"%s\n" // msaa
		"%s\n" // sample shading
		"%s\n" // Sampler binding
		"%s\n" // storage buffer
		"%s\n" // shader5
		"%s\n" // Geometry point size
		"%s\n" // AEP
		"%s\n" // texture buffer
		"%s\n" // ES texture buffer

		// Precision defines for GLSL ES
		"%s\n"
		"%s\n"
		"%s\n"
		"%s\n"

		// Silly differences
		"#define float2 vec2\n"
		"#define float3 vec3\n"
		"#define float4 vec4\n"
		"#define uint2 uvec2\n"
		"#define uint3 uvec3\n"
		"#define uint4 uvec4\n"
		"#define int2 ivec2\n"
		"#define int3 ivec3\n"
		"#define int4 ivec4\n"

		// hlsl to glsl function translation
		"#define frac fract\n"
		"#define lerp mix\n"

		// Terrible hacks, look at DriverDetails.h
		"%s\n" // replace textureSize as constant
		"%s\n" // wipe out all centroid usages

		, GetGLSLVersionString().c_str()
		, v<GLSL_140 ? "#extension GL_ARB_uniform_buffer_object : enable" : ""
		, !is_glsles && g_ActiveConfig.backend_info.bSupportsEarlyZ ? "#extension GL_ARB_shader_image_load_store : enable" : ""
		, (g_ActiveConfig.backend_info.bSupportsBindingLayout && v < GLSLES_310) ? "#extension GL_ARB_shading_language_420pack : enable" : ""
		, (g_ogl_config.bSupportsMSAA && v < GLSL_150) ? "#extension GL_ARB_texture_multisample : enable" : ""
		, (g_ogl_config.bSupportSampleShading) ? "#extension GL_ARB_sample_shading : enable" : ""
		, g_ActiveConfig.backend_info.bSupportsBindingLayout ? "#define SAMPLER_BINDING(x) layout(binding = x)" : "#define SAMPLER_BINDING(x)"
		, g_ActiveConfig.backend_info.bSupportsBBox ? "#extension GL_ARB_shader_storage_buffer_object : enable" : ""
		, !is_glsles && g_ActiveConfig.backend_info.bSupportsGSInstancing ? "#extension GL_ARB_gpu_shader5 : enable" : ""
		, SupportedESPointSize.c_str()
		, g_ogl_config.bSupportsAEP ? "#extension GL_ANDROID_extension_pack_es31a : enable" : ""
		, v<GLSL_140 && g_ActiveConfig.backend_info.bSupportsPaletteConversion ? "#extension GL_ARB_texture_buffer_object : enable" : ""
		, SupportedESTextureBuffer.c_str()

		, is_glsles ? "precision highp float;" : ""
		, is_glsles ? "precision highp int;" : ""
		, is_glsles ? "precision highp sampler2DArray;" : ""
		, (is_glsles && g_ActiveConfig.backend_info.bSupportsPaletteConversion) ? "precision highp usamplerBuffer;" : ""

		, DriverDetails::HasBug(DriverDetails::BUG_BROKENTEXTURESIZE) ? "#define textureSize(x, y) ivec2(1, 1)" : ""
		, DriverDetails::HasBug(DriverDetails::BUG_BROKENCENTROID) ? "#define centroid" : ""
	);
}
void ProgramShaderCache::CreateHeader()
{
	GLSL_VERSION v = g_ogl_config.eSupportedGLSLVersion;
	bool is_glsles = v >= GLSLES_300;
	std::string SupportedESPointSize;
	std::string SupportedESTextureBuffer;
	switch (g_ogl_config.SupportedESPointSize)
	{
	case 1: SupportedESPointSize = "#extension GL_OES_geometry_point_size : enable"; break;
	case 2: SupportedESPointSize = "#extension GL_EXT_geometry_point_size : enable"; break;
	default: SupportedESPointSize = ""; break;
	}

	switch (g_ogl_config.SupportedESTextureBuffer)
	{
	case ES_TEXBUF_TYPE::TEXBUF_EXT:
		SupportedESTextureBuffer = "#extension GL_EXT_texture_buffer : enable";
	break;
	case ES_TEXBUF_TYPE::TEXBUF_OES:
		SupportedESTextureBuffer = "#extension GL_OES_texture_buffer : enable";
	break;
	case ES_TEXBUF_TYPE::TEXBUF_CORE:
	case ES_TEXBUF_TYPE::TEXBUF_NONE:
		SupportedESTextureBuffer = "";
	break;
	}

	const char* earlyz_string = "";
	if (!is_glsles && g_ActiveConfig.backend_info.bSupportsEarlyZ)
	{
		if (g_ogl_config.bSupportsEarlyFragmentTests)
		{
			earlyz_string = "#extension GL_ARB_shader_image_load_store : enable\n"
			                "#define FORCE_EARLY_Z layout(early_fragment_tests) in\n";
		}
		else if(g_ogl_config.bSupportsConservativeDepth)
		{
			// See PixelShaderGen for details about this fallback.
			earlyz_string = "#extension GL_ARB_conservative_depth : enable\n"
			                "#define FORCE_EARLY_Z layout(depth_unchanged) out float gl_FragDepth\n";
		}
	}

	snprintf(s_glsl_header, sizeof(s_glsl_header),
		"%s\n"
		"%s\n" // ubo
		"%s\n" // early-z
		"%s\n" // 420pack
		"%s\n" // msaa
		"%s\n" // Sampler binding
		"%s\n" // storage buffer
		"%s\n" // shader5
		"%s\n" // SSAA
		"%s\n" // Geometry point size
		"%s\n" // AEP
		"%s\n" // texture buffer
		"%s\n" // ES texture buffer
		"%s\n" // ES dual source blend

		// Precision defines for GLSL ES
		"%s\n"
		"%s\n"
		"%s\n"
		"%s\n"
		"%s\n"

		// Silly differences
		"#define float2 vec2\n"
		"#define float3 vec3\n"
		"#define float4 vec4\n"
		"#define uint2 uvec2\n"
		"#define uint3 uvec3\n"
		"#define uint4 uvec4\n"
		"#define int2 ivec2\n"
		"#define int3 ivec3\n"
		"#define int4 ivec4\n"

		// hlsl to glsl function translation
		"#define frac fract\n"
		"#define lerp mix\n"

		, GetGLSLVersionString().c_str()
		, v < GLSL_140 ? "#extension GL_ARB_uniform_buffer_object : enable" : ""
		, earlyz_string
		, (g_ActiveConfig.backend_info.bSupportsBindingLayout && v < GLSLES_310) ? "#extension GL_ARB_shading_language_420pack : enable" : ""
		, (g_ogl_config.bSupportsMSAA && v < GLSL_150) ? "#extension GL_ARB_texture_multisample : enable" : ""
		, g_ActiveConfig.backend_info.bSupportsBindingLayout ? "#define SAMPLER_BINDING(x) layout(binding = x)" : "#define SAMPLER_BINDING(x)"
		, g_ActiveConfig.backend_info.bSupportsBBox ? "#extension GL_ARB_shader_storage_buffer_object : enable" : ""
		, v < GLSL_400 && g_ActiveConfig.backend_info.bSupportsGSInstancing ? "#extension GL_ARB_gpu_shader5 : enable" : ""
		, v < GLSL_400 && g_ActiveConfig.backend_info.bSupportsSSAA ? "#extension GL_ARB_sample_shading : enable" : ""
		, SupportedESPointSize.c_str()
		, g_ogl_config.bSupportsAEP ? "#extension GL_ANDROID_extension_pack_es31a : enable" : ""
		, v < GLSL_140 && g_ActiveConfig.backend_info.bSupportsPaletteConversion ? "#extension GL_ARB_texture_buffer_object : enable" : ""
		, SupportedESTextureBuffer.c_str()
		, is_glsles && g_ActiveConfig.backend_info.bSupportsDualSourceBlend ? "#extension GL_EXT_blend_func_extended : enable" : ""

		, is_glsles ? "precision highp float;" : ""
		, is_glsles ? "precision highp int;" : ""
		, is_glsles ? "precision highp sampler2DArray;" : ""
		, (is_glsles && g_ActiveConfig.backend_info.bSupportsPaletteConversion) ? "precision highp usamplerBuffer;" : ""
		, v > GLSLES_300 ? "precision highp sampler2DMS;" : ""
	);
}
void ProgramShaderCache::CreateHeader()
{
	GLSL_VERSION v = g_ogl_config.eSupportedGLSLVersion;
	bool is_glsles = v >= GLSLES_300;
	std::string SupportedESPointSize;
	std::string SupportedESTextureBuffer;
	switch (g_ogl_config.SupportedESPointSize)
	{
	case 1: SupportedESPointSize = "#extension GL_OES_geometry_point_size : enable"; break;
	case 2: SupportedESPointSize = "#extension GL_EXT_geometry_point_size : enable"; break;
	default: SupportedESPointSize = ""; break;
	}

	switch (g_ogl_config.SupportedESTextureBuffer)
	{
	case ES_TEXBUF_TYPE::TEXBUF_EXT:
		SupportedESTextureBuffer = "#extension GL_EXT_texture_buffer : enable";
		break;
	case ES_TEXBUF_TYPE::TEXBUF_OES:
		SupportedESTextureBuffer = "#extension GL_OES_texture_buffer : enable";
		break;
	case ES_TEXBUF_TYPE::TEXBUF_CORE:
	case ES_TEXBUF_TYPE::TEXBUF_NONE:
		SupportedESTextureBuffer = "";
		break;
	}

	snprintf(s_glsl_header, sizeof(s_glsl_header),
		"%s\n"
		"%s\n" // ubo
		"%s\n" // early-z
		"%s\n" // 420pack
		"%s\n" // msaa
		"%s\n" // sample shading
		"%s\n" // Sampler binding
		"%s\n" // storage buffer
		"%s\n" // shader5
		"%s\n" // SSAA
		"%s\n" // Geometry point size
		"%s\n" // AEP
		"%s\n" // texture buffer
		"%s\n" // ES texture buffer
		"%s\n" // ES dual source blend

		// Precision defines for GLSL ES
		"%s\n"
		"%s\n"
		"%s\n"
		"%s\n"
		"%s\n"

		// Silly differences
		"#define float2 vec2\n"
		"#define float3 vec3\n"
		"#define float4 vec4\n"
		"#define uint2 uvec2\n"
		"#define uint3 uvec3\n"
		"#define uint4 uvec4\n"
		"#define int2 ivec2\n"
		"#define int3 ivec3\n"
		"#define int4 ivec4\n"
		"#define float1x1 mat1\n"
		"#define float2x2 mat2\n"
		"#define float3x3 mat3\n"
		"#define float4x4 mat4\n"
		"#define float4x3 mat4x3\n"
		"#define float3x4 mat3x4\n"

		// hlsl to glsl function translation
		"#define frac fract\n"
		"#define lerp mix\n"
		"#define saturate(x) clamp(x, 0.0, 1.0)\n"
		"#define mul(x, y) (y * x)\n"
		"#define ddx dFdx\n"
		"#define ddy dFdy\n"
		"#define rsqrt inversesqrt\n"
		


		, GetGLSLVersionString().c_str()
		, v<GLSL_140 ? "#extension GL_ARB_uniform_buffer_object : enable" : ""
		, !is_glsles && g_ActiveConfig.backend_info.bSupportsEarlyZ ? "#extension GL_ARB_shader_image_load_store : enable" : ""
		, (g_ActiveConfig.backend_info.bSupportsBindingLayout && v < GLSLES_310) ? "#extension GL_ARB_shading_language_420pack : enable" : ""
		, (g_ogl_config.bSupportsMSAA && v < GLSL_150) ? "#extension GL_ARB_texture_multisample : enable" : ""
		, (v < GLSLES_300 && g_ActiveConfig.backend_info.bSupportsSSAA) ? "#extension GL_ARB_sample_shading : enable" : ""
		, g_ActiveConfig.backend_info.bSupportsBindingLayout ? "#define SAMPLER_BINDING(x) layout(binding = x)" : "#define SAMPLER_BINDING(x)"
		, g_ActiveConfig.backend_info.bSupportsBBox ? "#extension GL_ARB_shader_storage_buffer_object : enable" : ""
		, !is_glsles && g_ActiveConfig.backend_info.bSupportsGSInstancing ? "#extension GL_ARB_gpu_shader5 : enable" : ""
		, SupportedESPointSize.c_str()
		, g_ogl_config.bSupportsAEP ? "#extension GL_ANDROID_extension_pack_es31a : enable" : ""
		, v<GLSL_140 && g_ActiveConfig.backend_info.bSupportsPaletteConversion ? "#extension GL_ARB_texture_buffer_object : enable" : ""
		, v < GLSL_400 && g_ActiveConfig.backend_info.bSupportsSSAA ? "#extension GL_ARB_sample_shading : enable" : ""
		, SupportedESTextureBuffer.c_str()
		, is_glsles && g_ActiveConfig.backend_info.bSupportsDualSourceBlend ? "#extension GL_EXT_blend_func_extended : enable" : ""
		, is_glsles ? "precision highp float;" : ""
		, is_glsles ? "precision highp int;" : ""
		, is_glsles ? "precision highp sampler2DArray;" : ""
		, (is_glsles && g_ActiveConfig.backend_info.bSupportsPaletteConversion) ? "precision highp usamplerBuffer;" : ""
		, v > GLSLES_300 ? "precision highp sampler2DMS;" : ""
	);
}