MSL vs/fs shaders use spirv-cross
This commit is contained in:
parent
dbdb41d5c8
commit
5dba3a93af
@ -51,7 +51,7 @@ vec4 SampleAtlas( vec3 page, vec2 uv )
|
||||
uv *= BorderScale;
|
||||
uv += BorderOffset;
|
||||
|
||||
vec2 offset = floor( page.xy * 255 + 0.5 );
|
||||
vec2 offset = floor( page.xy * 255.0 + 0.5 );
|
||||
|
||||
return texture2D( s_vt_texture_atlas, ( offset + uv ) * AtlasScale );
|
||||
}
|
||||
@ -60,10 +60,10 @@ vec4 SampleAtlas( vec3 page, vec2 uv )
|
||||
vec4 VirtualTextureTrilinear( vec2 uv )
|
||||
{
|
||||
float miplevel = MipLevel( uv, VirtualTextureSize );
|
||||
miplevel = clamp( miplevel, 0, log2( PageTableSize )-1 );
|
||||
miplevel = clamp( miplevel, 0.0, log2( PageTableSize )-1.0 );
|
||||
|
||||
float mip1 = floor( miplevel );
|
||||
float mip2 = mip1 + 1;
|
||||
float mip2 = mip1 + 1.0;
|
||||
float mipfrac = miplevel - mip1;
|
||||
|
||||
vec3 page1 = SampleTable( uv, mip1 );
|
||||
|
@ -1,5 +1,5 @@
|
||||
vec3 a_position : POSITION;
|
||||
ivec4 a_indices : BLENDINDICES;
|
||||
uvec4 a_indices : BLENDINDICES;
|
||||
vec4 a_color0 : COLOR0;
|
||||
vec2 a_texcoord0 : TEXCOORD0;
|
||||
|
||||
|
@ -36,7 +36,7 @@
|
||||
# define ARRAY_END() }
|
||||
#endif // BGFX_SHADER_LANGUAGE_GLSL
|
||||
|
||||
#if BGFX_SHADER_LANGUAGE_HLSL || BGFX_SHADER_LANGUAGE_PSSL || BGFX_SHADER_LANGUAGE_SPIRV
|
||||
#if BGFX_SHADER_LANGUAGE_HLSL || BGFX_SHADER_LANGUAGE_PSSL || BGFX_SHADER_LANGUAGE_SPIRV || BGFX_SHADER_LANGUAGE_METAL
|
||||
# define CONST(_x) static const _x
|
||||
# define dFdx(_x) ddx(_x)
|
||||
# define dFdy(_y) ddy(-_y)
|
||||
@ -53,8 +53,8 @@
|
||||
# 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
|
||||
# if BGFX_SHADER_LANGUAGE_HLSL > 3 || BGFX_SHADER_LANGUAGE_PSSL || BGFX_SHADER_LANGUAGE_SPIRV || BGFX_SHADER_LANGUAGE_METAL
|
||||
# if BGFX_SHADER_LANGUAGE_HLSL > 4 || BGFX_SHADER_LANGUAGE_PSSL || BGFX_SHADER_LANGUAGE_SPIRV || BGFX_SHADER_LANGUAGE_METAL
|
||||
# define dFdxCoarse(_x) ddx_coarse(_x)
|
||||
# define dFdxFine(_x) ddx_fine(_x)
|
||||
# define dFdyCoarse(_y) ddy_coarse(-_y)
|
||||
@ -88,7 +88,7 @@ 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
|
||||
# if !BGFX_SHADER_LANGUAGE_SPIRV && !BGFX_SHADER_LANGUAGE_METAL
|
||||
uint packHalf2x16(vec2 _x)
|
||||
{
|
||||
return (f32tof16(_x.y)<<16) | f32tof16(_x.x);
|
||||
@ -98,7 +98,7 @@ vec2 unpackHalf2x16(uint _x)
|
||||
{
|
||||
return vec2(f16tof32(_x & 0xffff), f16tof32(_x >> 16) );
|
||||
}
|
||||
# endif // !BGFX_SHADER_LANGUAGE_SPIRV
|
||||
# endif // !BGFX_SHADER_LANGUAGE_SPIRV && !BGFX_SHADER_LANGUAGE_METAL
|
||||
|
||||
struct BgfxSampler2D
|
||||
{
|
||||
@ -560,11 +560,11 @@ vec2 vec2_splat(float _x) { return vec2(_x, _x); }
|
||||
vec3 vec3_splat(float _x) { return vec3(_x, _x, _x); }
|
||||
vec4 vec4_splat(float _x) { return vec4(_x, _x, _x, _x); }
|
||||
|
||||
#if BGFX_SHADER_LANGUAGE_GLSL >= 130 || BGFX_SHADER_LANGUAGE_HLSL || BGFX_SHADER_LANGUAGE_PSSL || BGFX_SHADER_LANGUAGE_SPIRV
|
||||
#if BGFX_SHADER_LANGUAGE_GLSL >= 130 || BGFX_SHADER_LANGUAGE_HLSL || BGFX_SHADER_LANGUAGE_PSSL || BGFX_SHADER_LANGUAGE_SPIRV || BGFX_SHADER_LANGUAGE_METAL
|
||||
uvec2 uvec2_splat(uint _x) { return uvec2(_x, _x); }
|
||||
uvec3 uvec3_splat(uint _x) { return uvec3(_x, _x, _x); }
|
||||
uvec4 uvec4_splat(uint _x) { return uvec4(_x, _x, _x, _x); }
|
||||
#endif // BGFX_SHADER_LANGUAGE_GLSL >= 130 || BGFX_SHADER_LANGUAGE_HLSL || BGFX_SHADER_LANGUAGE_PSSL || BGFX_SHADER_LANGUAGE_SPIRV
|
||||
#endif // BGFX_SHADER_LANGUAGE_GLSL >= 130 || BGFX_SHADER_LANGUAGE_HLSL || BGFX_SHADER_LANGUAGE_PSSL || BGFX_SHADER_LANGUAGE_SPIRV || BGFX_SHADER_LANGUAGE_METAL
|
||||
|
||||
mat4 mtxFromRows(vec4 _0, vec4 _1, vec4 _2, vec4 _3)
|
||||
{
|
||||
|
@ -1030,7 +1030,14 @@ namespace bgfx
|
||||
else if (0 == bx::strCmpI(platform, "ios") )
|
||||
{
|
||||
preprocessor.setDefine("BX_PLATFORM_IOS=1");
|
||||
preprocessor.setDefine("BGFX_SHADER_LANGUAGE_GLSL=1");
|
||||
if (metal)
|
||||
{
|
||||
preprocessor.setDefine("BGFX_SHADER_LANGUAGE_METAL=1");
|
||||
}
|
||||
else
|
||||
{
|
||||
preprocessor.setDefine("BGFX_SHADER_LANGUAGE_GLSL=1");
|
||||
}
|
||||
}
|
||||
else if (0 == bx::strCmpI(platform, "linux") )
|
||||
{
|
||||
@ -1047,11 +1054,7 @@ namespace bgfx
|
||||
else if (0 == bx::strCmpI(platform, "osx") )
|
||||
{
|
||||
preprocessor.setDefine("BX_PLATFORM_OSX=1");
|
||||
if (_options.shaderType == 'c')
|
||||
{
|
||||
preprocessor.setDefine("BGFX_SHADER_LANGUAGE_SPIRV=1");
|
||||
}
|
||||
else
|
||||
if (!metal)
|
||||
{
|
||||
preprocessor.setDefine(glslDefine);
|
||||
}
|
||||
@ -1510,8 +1513,7 @@ namespace bgfx
|
||||
else
|
||||
{
|
||||
if (0 != glsl
|
||||
|| 0 != essl
|
||||
|| 0 != metal)
|
||||
|| 0 != essl)
|
||||
{
|
||||
if (0 == essl)
|
||||
{
|
||||
@ -1937,8 +1939,7 @@ namespace bgfx
|
||||
}
|
||||
|
||||
if (0 != glsl
|
||||
|| 0 != essl
|
||||
|| 0 != metal)
|
||||
|| 0 != essl)
|
||||
{
|
||||
if (!bx::strFind(preprocessor.m_preprocessed.c_str(), "layout(std430").isEmpty() )
|
||||
{
|
||||
@ -1961,21 +1962,14 @@ namespace bgfx
|
||||
|
||||
if (0 == essl)
|
||||
{
|
||||
const bool need130 = 0 != metal || (120 == glsl && (false
|
||||
const bool need130 = (120 == glsl && (false
|
||||
|| !bx::findIdentifierMatch(input, s_130).isEmpty()
|
||||
|| usesInterpolationQualifiers
|
||||
|| usesTexelFetch
|
||||
) );
|
||||
|
||||
if (0 != metal)
|
||||
{
|
||||
bx::stringPrintf(code, "#version 130\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
bx::stringPrintf(code, "#version %s\n", need130 ? "130" : _options.profile.c_str());
|
||||
glsl = 130;
|
||||
}
|
||||
bx::stringPrintf(code, "#version %s\n", need130 ? "130" : _options.profile.c_str());
|
||||
glsl = 130;
|
||||
|
||||
if (need130)
|
||||
{
|
||||
@ -2211,7 +2205,10 @@ namespace bgfx
|
||||
, "#define ivec2 vec2\n"
|
||||
"#define ivec3 vec3\n"
|
||||
"#define ivec4 vec4\n"
|
||||
);
|
||||
"#define uvec2 vec2\n"
|
||||
"#define uvec3 vec3\n"
|
||||
"#define uvec4 vec4\n"
|
||||
);
|
||||
}
|
||||
}
|
||||
else
|
||||
@ -2265,9 +2262,9 @@ namespace bgfx
|
||||
code += _comment;
|
||||
code += preprocessor.m_preprocessed;
|
||||
|
||||
if (0 != spirv)
|
||||
if (0 != spirv || 0 != metal)
|
||||
{
|
||||
compiled = compileSPIRVShader(_options, 0, code, _writer);
|
||||
compiled = compileSPIRVShader(_options, metal ? BX_MAKEFOURCC('M', 'T', 'L', 0) : 0, code, _writer);
|
||||
}
|
||||
else if (0 != pssl)
|
||||
{
|
||||
|
@ -849,6 +849,12 @@ namespace bgfx { namespace spirv
|
||||
msl.set_decoration(resource.id, spv::DecorationBinding, binding + 1);
|
||||
}
|
||||
|
||||
for (auto &resource : resources.separate_images)
|
||||
{
|
||||
std::string name = msl.get_name(resource.id);
|
||||
if (name.size() > 7 && 0 == bx::strCmp(name.c_str() + name.length() - 7, "Texture") )
|
||||
msl.set_name(resource.id, name.substr(0, name.length() - 7));
|
||||
}
|
||||
std::string source = msl.compile();
|
||||
|
||||
if ('c' == _options.shaderType)
|
||||
|
Loading…
Reference in New Issue
Block a user