diff --git a/src/bgfx_compute.sh b/src/bgfx_compute.sh index 04419d413..32cdac319 100644 --- a/src/bgfx_compute.sh +++ b/src/bgfx_compute.sh @@ -12,36 +12,6 @@ #if 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); } - -uint packHalf2x16(vec2 _x) -{ - return (f32tof16(_x.x)<<16) | f32tof16(_x.y); -} - -vec2 unpackHalf2x16(uint _x) -{ - return vec2(f16tof32(_x >> 16), f16tof32(_x) ); -} - #define SHARED groupshared #define r32ui uint diff --git a/src/bgfx_shader.sh b/src/bgfx_shader.sh index a675fb6e6..29f80d0f4 100644 --- a/src/bgfx_shader.sh +++ b/src/bgfx_shader.sh @@ -46,6 +46,41 @@ # define dFdyFine(_y) ddy_fine(-_y) # endif // BGFX_SHADER_LANGUAGE_HLSL > 4 +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); } + +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); } + +uint packHalf2x16(vec2 _x) +{ + return (f32tof16(_x.x)<<16) | f32tof16(_x.y); +} + +vec2 unpackHalf2x16(uint _x) +{ + return vec2(f16tof32(_x >> 16), f16tof32(_x) ); +} + struct BgfxSampler2D { SamplerState m_sampler; diff --git a/tools/shaderc/shaderc.cpp b/tools/shaderc/shaderc.cpp index 915119afc..a5b14edcf 100644 --- a/tools/shaderc/shaderc.cpp +++ b/tools/shaderc/shaderc.cpp @@ -70,6 +70,23 @@ namespace bgfx NULL }; + static const char* s_ARB_gpu_shader5[] = + { + "bitfieldReverse", + "floatBitsToInt", + "floatBitsToUint", + "intBitsToFloat", + "uintBitsToFloat", + NULL + }; + + static const char* s_ARB_shading_language_packing[] = + { + "packHalf2x16", + "unpackHalf2x16", + NULL + }; + static const char* s_130[] = { "uint", @@ -1706,7 +1723,9 @@ namespace bgfx { std::string code; - bool hasTextureLod = NULL != bx::findIdentifierMatch(input, s_ARB_shader_texture_lod /*EXT_shader_texture_lod*/); + const bool hasTextureLod = NULL != bx::findIdentifierMatch(input, s_ARB_shader_texture_lod /*EXT_shader_texture_lod*/); + const bool hasShader5 = NULL != bx::findIdentifierMatch(input, s_ARB_gpu_shader5); + const bool hasShaderPacking = NULL != bx::findIdentifierMatch(input, s_ARB_shading_language_packing); if (0 == essl) { @@ -1723,6 +1742,20 @@ namespace bgfx bx::stringPrintf(code, "#version %s\n", need130 ? "130" : profile); } + if (hasShader5) + { + bx::stringPrintf(code + , "#extension GL_ARB_gpu_shader5 : enable\n" + ); + } + + if (hasShaderPacking) + { + bx::stringPrintf(code + , "#extension GL_ARB_shading_language_packing : enable\n" + ); + } + bx::stringPrintf(code , "#define bgfxShadow2D shadow2D\n" "#define bgfxShadow2DProj shadow2DProj\n" @@ -1772,6 +1805,20 @@ namespace bgfx ); } + if (hasShader5) + { + bx::stringPrintf(code + , "#extension GL_ARB_gpu_shader5 : enable\n" + ); + } + + if (hasShaderPacking) + { + bx::stringPrintf(code + , "#extension GL_ARB_shading_language_packing : enable\n" + ); + } + if (NULL != bx::findIdentifierMatch(input, "gl_FragDepth") ) { bx::stringPrintf(code