 			#	define bvec3 bool3
 			#	define bvec4 bool4
 
-			#	if BGFX_SHADER_LANGUAGE_HLSL > 3
+			#	if BGFX_SHADER_LANGUAGE_HLSL > 4
+			#		define REGISTER(_type, _reg) register(_type[_reg])
+			#	else
+			#		define REGISTER(_type, _reg) register(_type ## _reg)
+			#	endif // BGFX_SHADER_LANGUAGE_HLSL
+
+			#	if BGFX_SHADER_LANGUAGE_HLSL > 3 || BGFX_SHADER_LANGUAGE_PSSL || BGFX_SHADER_LANGUAGE_SPIRV
+			#		if BGFX_SHADER_LANGUAGE_HLSL > 4 || BGFX_SHADER_LANGUAGE_PSSL || BGFX_SHADER_LANGUAGE_SPIRV
+			#			define dFdxCoarse(_x) ddx_coarse(_x)
+			#			define dFdxFine(_x)   ddx_fine(_x)
+			#			define dFdyCoarse(_y) ddy_coarse(-_y)
+			#			define dFdyFine(_y)   ddy_fine(-_y)
+			#		endif // BGFX_SHADER_LANGUAGE_HLSL > 4
+
+			#		if BGFX_SHADER_LANGUAGE_HLSL
+			float intBitsToFloat(int   _x) { return asfloat(_x); }
+			vec2  intBitsToFloat(uint2 _x) { return asfloat(_x); }
+			vec3  intBitsToFloat(uint3 _x) { return asfloat(_x); }
+			vec4  intBitsToFloat(uint4 _x) { return asfloat(_x); }
+			#		endif // BGFX_SHADER_LANGUAGE_HLSL
+
+			float uintBitsToFloat(uint  _x) { return asfloat(_x); }
+			vec2  uintBitsToFloat(uint2 _x) { return asfloat(_x); }
+			vec3  uintBitsToFloat(uint3 _x) { return asfloat(_x); }
+			vec4  uintBitsToFloat(uint4 _x) { return asfloat(_x); }
+
+			uint  floatBitsToUint(float _x) { return asuint(_x); }
+			uvec2 floatBitsToUint(vec2  _x) { return asuint(_x); }
+			uvec3 floatBitsToUint(vec3  _x) { return asuint(_x); }
+			uvec4 floatBitsToUint(vec4  _x) { return asuint(_x); }
+
+			int   floatBitsToInt(float _x) { return asint(_x); }
+			ivec2 floatBitsToInt(vec2  _x) { return asint(_x); }
+			ivec3 floatBitsToInt(vec3  _x) { return asint(_x); }
+			ivec4 floatBitsToInt(vec4  _x) { return asint(_x); }
+
+			uint  bitfieldReverse(uint  _x) { return reversebits(_x); }
+			uint2 bitfieldReverse(uint2 _x) { return reversebits(_x); }
+			uint3 bitfieldReverse(uint3 _x) { return reversebits(_x); }
+			uint4 bitfieldReverse(uint4 _x) { return reversebits(_x); }
+
+			#		if !BGFX_SHADER_LANGUAGE_SPIRV
+			uint packHalf2x16(vec2 _x)
+			{
+				return (f32tof16(_x.y)<<16) | f32tof16(_x.x);
+			}
+
+			vec2 unpackHalf2x16(uint _x)
+			{
+				return vec2(f16tof32(_x & 0xffff), f16tof32(_x >> 16) );
+			}
+			#		endif // !BGFX_SHADER_LANGUAGE_SPIRV
+
 			struct BgfxSampler2D
 			{
 				SamplerState m_sampler;
 				Texture2D m_texture;
 			};
 
-			vec4 bgfxTexture2D(BgfxSampler2D _sampler, vec2 _coord)
-			{
-				return _sampler.m_texture.Sample(_sampler.m_sampler, _coord);
-			}
-
-			vec4 bgfxTexture2DLod(BgfxSampler2D _sampler, vec2 _coord, float _level)
-			{
-				return _sampler.m_texture.SampleLevel(_sampler.m_sampler, _coord, _level);
-			}
-
-			vec4 bgfxTexture2DProj(BgfxSampler2D _sampler, vec3 _coord)
-			{
-				vec2 coord = _coord.xy * rcp(_coord.z);
-				return _sampler.m_texture.Sample(_sampler.m_sampler, coord);
-			}
-
-			vec4 bgfxTexture2DProj(BgfxSampler2D _sampler, vec4 _coord)
-			{
-				vec2 coord = _coord.xy * rcp(_coord.w);
-				return _sampler.m_texture.Sample(_sampler.m_sampler, coord);
-			}
+			struct BgfxISampler2D
+			{
+				Texture2D<ivec4> m_texture;
+			};
+
+			struct BgfxUSampler2D
+			{
+				Texture2D<uvec4> m_texture;
+			};
+
+			struct BgfxSampler2DArray
+			{
+				SamplerState m_sampler;
+				Texture2DArray m_texture;
+			};
 
 			struct BgfxSampler2DShadow
 			{


			#endif // __cplusplus

			vec4 encodeRE8(float _r)
			{
				float exponent = ceil(log2(_r) );

				return _sampler.m_texture.SampleLevel(_sampler.m_sampler, _coord, _level);
			}

			vec4 bgfxTexelFetch(BgfxSampler2D _sampler, ivec2 _coord, int _lod)
			{
				return _sampler.m_texture.Load(ivec3(_coord, _lod) );
			}

			ivec4 bgfxTexelFetch(BgfxISampler2D _sampler, ivec2 _coord, int _lod)
			{
				return _sampler.m_texture.Load(ivec3(_coord, _lod) );
			}

			uvec4 bgfxTexelFetch(BgfxUSampler2D _sampler, ivec2 _coord, int _lod)
			{
				return _sampler.m_texture.Load(ivec3(_coord, _lod) );
			}

			vec4 bgfxTexelFetch(BgfxSampler2DMS _sampler, ivec2 _coord, int _sampleIdx)
			{
				return _sampler.m_texture.Load(_coord, _sampleIdx);
			}

			vec4 bgfxTexelFetch(BgfxSampler3D _sampler, ivec3 _coord, int _lod)
			{
				return _sampler.m_texture.Load(ivec4(_coord, _lod) );
			}

			#		define SAMPLER2D(_name, _reg) \\
						uniform SamplerState _name ## Sampler : REGISTER(s, _reg); \\
						uniform Texture2D _name ## Texture : REGISTER(t, _reg); \\
						static BgfxSampler2D _name = { _name ## Sampler, _name ## Texture }
			#		define ISAMPLER2D(_name, _reg) \\
						uniform Texture2D<ivec4> _name ## Texture : REGISTER(t, _reg); \\
						static BgfxISampler2D _name = { _name ## Texture }
			#		define USAMPLER2D(_name, _reg) \\
						uniform Texture2D<uvec4> _name ## Texture : REGISTER(t, _reg); \\
						static BgfxUSampler2D _name = { _name ## Texture }
			#		define sampler2D BgfxSampler2D
			#		define texture2D(_sampler, _coord) bgfxTexture2D(_sampler, _coord)
			#		define texture2DLod(_sampler, _coord, _level) bgfxTexture2DLod(_sampler, _coord, _level)
			#		define texture2DProj(_sampler, _coord) bgfxTexture2DProj(_sampler, _coord)
			#		define texture2DGrad(_sampler, _coord, _dPdx, _dPdy) bgfxTexture2DGrad(_sampler, _coord, _dPdx, _dPdy)

			#		define SAMPLER2DARRAY(_name, _reg) \\
						uniform SamplerState _name ## Sampler : REGISTER(s, _reg); \\
						uniform Texture2DArray _name ## Texture : REGISTER(t, _reg); \\
						static BgfxSampler2DArray _name = { _name ## Sampler, _name ## Texture }
			#		define sampler2DArray BgfxSampler2DArray
			#		define texture2DArray(_sampler, _coord) bgfxTexture2DArray(_sampler, _coord)
			#		define texture2DArrayLod(_sampler, _coord, _lod) bgfxTexture2DArrayLod(_sampler, _coord, _lod)

			#		define SAMPLER2DMS(_name, _reg) \\
						uniform Texture2DMS<vec4> _name ## Texture : REGISTER(t, _reg); \\
						static BgfxSampler2DMS _name = { _name ## Texture }
			#		define sampler2DMS BgfxSampler2DMS

			#		define SAMPLER2DSHADOW(_name, _reg) \\
						uniform SamplerComparisonState _name ## SamplerComparison : REGISTER(s, _reg); \\
						uniform Texture2D _name ## Texture : REGISTER(t, _reg); \\
						static BgfxSampler2DShadow _name = { _name ## SamplerComparison, _name ## Texture }
			#		define sampler2DShadow BgfxSampler2DShadow
			#		define shadow2D(_sampler, _coord) bgfxShadow2D(_sampler, _coord)
			#		define shadow2DProj(_sampler, _coord) bgfxShadow2DProj(_sampler, _coord)

			#		define SAMPLER3D(_name, _reg) \\
						uniform SamplerState _name ## Sampler : REGISTER(s, _reg); \\
						uniform Texture3D _name ## Texture : REGISTER(t, _reg); \\
						static BgfxSampler3D _name = { _name ## Sampler, _name ## Texture }
			#		define ISAMPLER3D(_name, _reg) \\
						uniform Texture3D<ivec4> _name ## Texture : REGISTER(t, _reg); \\
						static BgfxISampler3D _name = { _name ## Texture }
			#		define USAMPLER3D(_name, _reg) \\
						uniform Texture3D<uvec4> _name ## Texture : REGISTER(t, _reg); \\
						static BgfxUSampler3D _name = { _name ## Texture }
			#		define sampler3D BgfxSampler3D
			#		define texture3D(_sampler, _coord) bgfxTexture3D(_sampler, _coord)
			#		define texture3DLod(_sampler, _coord, _level) bgfxTexture3DLod(_sampler, _coord, _level)

			#		define SAMPLERCUBE(_name, _reg) \\
						uniform SamplerState _name ## Sampler : REGISTER(s, _reg); \\
						uniform TextureCube _name ## Texture : REGISTER(t, _reg); \\
						static BgfxSamplerCube _name = { _name ## Sampler, _name ## Texture }
			#		define samplerCube BgfxSamplerCube
			#		define textureCube(_sampler, _coord) bgfxTextureCube(_sampler, _coord)
			#		define textureCubeLod(_sampler, _coord, _level) bgfxTextureCubeLod(_sampler, _coord, _level)

			#		define texelFetch(_sampler, _coord, _lod) bgfxTexelFetch(_sampler, _coord, _lod)
			#	else

			#		define sampler2DShadow sampler2D
