diff --git a/3rdparty/glslang/glslang/HLSL/hlslParseHelper.cpp b/3rdparty/glslang/glslang/HLSL/hlslParseHelper.cpp index b0fb5f4660..6ead2bb324 100644 --- a/3rdparty/glslang/glslang/HLSL/hlslParseHelper.cpp +++ b/3rdparty/glslang/glslang/HLSL/hlslParseHelper.cpp @@ -9527,6 +9527,8 @@ bool HlslParseContext::isInputBuiltIn(const TQualifier& qualifier) const case EbvSampleMask: case EbvSamplePosition: case EbvViewportIndex: + case EbvBaryCoordEXT: + case EbvBaryCoordNoPerspEXT: return language == EShLangFragment; case EbvGlobalInvocationId: case EbvLocalInvocationIndex: diff --git a/3rdparty/glslang/glslang/HLSL/hlslScanContext.cpp b/3rdparty/glslang/glslang/HLSL/hlslScanContext.cpp index e9edb61976..14b02ef4e8 100644 --- a/3rdparty/glslang/glslang/HLSL/hlslScanContext.cpp +++ b/3rdparty/glslang/glslang/HLSL/hlslScanContext.cpp @@ -526,6 +526,8 @@ void HlslScanContext::fillInKeywordMap() (*SemanticMap)["SV_DEPTHGREATEREQUAL"] = EbvFragDepthGreater; (*SemanticMap)["SV_DEPTHLESSEQUAL"] = EbvFragDepthLesser; (*SemanticMap)["SV_STENCILREF"] = EbvFragStencilRef; + (*SemanticMap)["SV_BARYCENTRICS"] = EbvBaryCoordEXT; + (*SemanticMap)["SV_BARYCENTRICS1"] = EbvBaryCoordNoPerspEXT; } void HlslScanContext::deleteKeywordMap() diff --git a/3rdparty/spirv-cross/spirv_msl.cpp b/3rdparty/spirv-cross/spirv_msl.cpp index f6d3aaa3bf..51e293f08f 100644 --- a/3rdparty/spirv-cross/spirv_msl.cpp +++ b/3rdparty/spirv-cross/spirv_msl.cpp @@ -12214,7 +12214,7 @@ string CompilerMSL::member_attribute_qualifier(const SPIRType &type, uint32_t in else quals = member_location_attribute_qualifier(type, index); - if (builtin == BuiltInBaryCoordKHR || builtin == BuiltInBaryCoordNoPerspKHR) + if (builtin == BuiltInBaryCoordKHR) { if (has_member_decoration(type.self, index, DecorationFlat) || has_member_decoration(type.self, index, DecorationCentroid) || @@ -12232,35 +12232,38 @@ string CompilerMSL::member_attribute_qualifier(const SPIRType &type, uint32_t in // FragCoord builtin; it's always noperspective on Metal. if (!type_is_integral(mbr_type) && (!is_builtin || builtin != BuiltInFragCoord)) { - if (has_member_decoration(type.self, index, DecorationFlat)) + if (builtin != BuiltInBaryCoordKHR && builtin != BuiltInBaryCoordNoPerspKHR) { - if (!quals.empty()) - quals += ", "; - quals += "flat"; - } - else if (has_member_decoration(type.self, index, DecorationCentroid)) - { - if (!quals.empty()) - quals += ", "; - if (has_member_decoration(type.self, index, DecorationNoPerspective)) - quals += "centroid_no_perspective"; - else - quals += "centroid_perspective"; - } - else if (has_member_decoration(type.self, index, DecorationSample)) - { - if (!quals.empty()) - quals += ", "; - if (has_member_decoration(type.self, index, DecorationNoPerspective)) - quals += "sample_no_perspective"; - else - quals += "sample_perspective"; - } - else if (has_member_decoration(type.self, index, DecorationNoPerspective)) - { - if (!quals.empty()) - quals += ", "; - quals += "center_no_perspective"; + if (has_member_decoration(type.self, index, DecorationFlat)) + { + if (!quals.empty()) + quals += ", "; + quals += "flat"; + } + else if (has_member_decoration(type.self, index, DecorationCentroid)) + { + if (!quals.empty()) + quals += ", "; + if (has_member_decoration(type.self, index, DecorationNoPerspective)) + quals += "centroid_no_perspective"; + else + quals += "centroid_perspective"; + } + else if (has_member_decoration(type.self, index, DecorationSample)) + { + if (!quals.empty()) + quals += ", "; + if (has_member_decoration(type.self, index, DecorationNoPerspective)) + quals += "sample_no_perspective"; + else + quals += "sample_perspective"; + } + else if (has_member_decoration(type.self, index, DecorationNoPerspective)) + { + if (!quals.empty()) + quals += ", "; + quals += "center_no_perspective"; + } } } diff --git a/bindings/bf/bgfx.bf b/bindings/bf/bgfx.bf index 6fb2ed9dc5..fae84dab13 100644 --- a/bindings/bf/bgfx.bf +++ b/bindings/bf/bgfx.bf @@ -1046,126 +1046,131 @@ public static class bgfx /// FragmentOrdering = 0x0000000000000040, + /// + /// Fragment barycentric coordinates are available in fragment shader. + /// + FragmentBarycentric = 0x0000000000000080, + /// /// Graphics debugger is present. /// - GraphicsDebugger = 0x0000000000000080, + GraphicsDebugger = 0x0000000000000100, /// /// HDR10 rendering is supported. /// - Hdr10 = 0x0000000000000100, + Hdr10 = 0x0000000000000200, /// /// HiDPI rendering is supported. /// - Hidpi = 0x0000000000000200, + Hidpi = 0x0000000000000400, /// /// Image Read/Write is supported. /// - ImageRw = 0x0000000000000400, + ImageRw = 0x0000000000000800, /// /// 32-bit indices are supported. /// - Index32 = 0x0000000000000800, + Index32 = 0x0000000000001000, /// /// Instancing is supported. /// - Instancing = 0x0000000000001000, + Instancing = 0x0000000000002000, /// /// Occlusion query is supported. /// - OcclusionQuery = 0x0000000000002000, + OcclusionQuery = 0x0000000000004000, /// /// Renderer is on separate thread. /// - RendererMultithreaded = 0x0000000000004000, + RendererMultithreaded = 0x0000000000008000, /// /// Multiple windows are supported. /// - SwapChain = 0x0000000000008000, + SwapChain = 0x0000000000010000, /// /// 2D texture array is supported. /// - Texture2dArray = 0x0000000000010000, + Texture2dArray = 0x0000000000020000, /// /// 3D textures are supported. /// - Texture3d = 0x0000000000020000, + Texture3d = 0x0000000000040000, /// /// Texture blit is supported. /// - TextureBlit = 0x0000000000040000, + TextureBlit = 0x0000000000080000, /// /// Transparent back buffer supported. /// - TransparentBackbuffer = 0x0000000000080000, - TextureCompareReserved = 0x0000000000100000, + TransparentBackbuffer = 0x0000000000100000, + TextureCompareReserved = 0x0000000000200000, /// /// Texture compare less equal mode is supported. /// - TextureCompareLequal = 0x0000000000200000, + TextureCompareLequal = 0x0000000000400000, /// /// Cubemap texture array is supported. /// - TextureCubeArray = 0x0000000000400000, + TextureCubeArray = 0x0000000000800000, /// /// CPU direct access to GPU texture memory. /// - TextureDirectAccess = 0x0000000000800000, + TextureDirectAccess = 0x0000000001000000, /// /// Read-back texture is supported. /// - TextureReadBack = 0x0000000001000000, + TextureReadBack = 0x0000000002000000, /// /// Vertex attribute half-float is supported. /// - VertexAttribHalf = 0x0000000002000000, + VertexAttribHalf = 0x0000000004000000, /// /// Vertex attribute 10_10_10_2 is supported. /// - VertexAttribUint10 = 0x0000000004000000, + VertexAttribUint10 = 0x0000000008000000, /// /// Rendering with VertexID only is supported. /// - VertexId = 0x0000000008000000, + VertexId = 0x0000000010000000, /// /// PrimitiveID is available in fragment shader. /// - PrimitiveId = 0x0000000010000000, + PrimitiveId = 0x0000000020000000, /// /// Viewport layer is available in vertex shader. /// - ViewportLayerArray = 0x0000000020000000, + ViewportLayerArray = 0x0000000040000000, /// /// Draw indirect with indirect count is supported. /// - DrawIndirectCount = 0x0000000040000000, + DrawIndirectCount = 0x0000000080000000, /// /// All texture compare modes are supported. /// - TextureCompareAll = 0x0000000000300000, + TextureCompareAll = 0x0000000000600000, } [AllowDuplicates] diff --git a/bindings/cs/bgfx.cs b/bindings/cs/bgfx.cs index 64fd470b30..16c352f28a 100644 --- a/bindings/cs/bgfx.cs +++ b/bindings/cs/bgfx.cs @@ -1045,126 +1045,131 @@ public enum CapsFlags : ulong /// FragmentOrdering = 0x0000000000000040, + /// + /// Fragment barycentric coordinates are available in fragment shader. + /// + FragmentBarycentric = 0x0000000000000080, + /// /// Graphics debugger is present. /// - GraphicsDebugger = 0x0000000000000080, + GraphicsDebugger = 0x0000000000000100, /// /// HDR10 rendering is supported. /// - Hdr10 = 0x0000000000000100, + Hdr10 = 0x0000000000000200, /// /// HiDPI rendering is supported. /// - Hidpi = 0x0000000000000200, + Hidpi = 0x0000000000000400, /// /// Image Read/Write is supported. /// - ImageRw = 0x0000000000000400, + ImageRw = 0x0000000000000800, /// /// 32-bit indices are supported. /// - Index32 = 0x0000000000000800, + Index32 = 0x0000000000001000, /// /// Instancing is supported. /// - Instancing = 0x0000000000001000, + Instancing = 0x0000000000002000, /// /// Occlusion query is supported. /// - OcclusionQuery = 0x0000000000002000, + OcclusionQuery = 0x0000000000004000, /// /// Renderer is on separate thread. /// - RendererMultithreaded = 0x0000000000004000, + RendererMultithreaded = 0x0000000000008000, /// /// Multiple windows are supported. /// - SwapChain = 0x0000000000008000, + SwapChain = 0x0000000000010000, /// /// 2D texture array is supported. /// - Texture2dArray = 0x0000000000010000, + Texture2dArray = 0x0000000000020000, /// /// 3D textures are supported. /// - Texture3d = 0x0000000000020000, + Texture3d = 0x0000000000040000, /// /// Texture blit is supported. /// - TextureBlit = 0x0000000000040000, + TextureBlit = 0x0000000000080000, /// /// Transparent back buffer supported. /// - TransparentBackbuffer = 0x0000000000080000, - TextureCompareReserved = 0x0000000000100000, + TransparentBackbuffer = 0x0000000000100000, + TextureCompareReserved = 0x0000000000200000, /// /// Texture compare less equal mode is supported. /// - TextureCompareLequal = 0x0000000000200000, + TextureCompareLequal = 0x0000000000400000, /// /// Cubemap texture array is supported. /// - TextureCubeArray = 0x0000000000400000, + TextureCubeArray = 0x0000000000800000, /// /// CPU direct access to GPU texture memory. /// - TextureDirectAccess = 0x0000000000800000, + TextureDirectAccess = 0x0000000001000000, /// /// Read-back texture is supported. /// - TextureReadBack = 0x0000000001000000, + TextureReadBack = 0x0000000002000000, /// /// Vertex attribute half-float is supported. /// - VertexAttribHalf = 0x0000000002000000, + VertexAttribHalf = 0x0000000004000000, /// /// Vertex attribute 10_10_10_2 is supported. /// - VertexAttribUint10 = 0x0000000004000000, + VertexAttribUint10 = 0x0000000008000000, /// /// Rendering with VertexID only is supported. /// - VertexId = 0x0000000008000000, + VertexId = 0x0000000010000000, /// /// PrimitiveID is available in fragment shader. /// - PrimitiveId = 0x0000000010000000, + PrimitiveId = 0x0000000020000000, /// /// Viewport layer is available in vertex shader. /// - ViewportLayerArray = 0x0000000020000000, + ViewportLayerArray = 0x0000000040000000, /// /// Draw indirect with indirect count is supported. /// - DrawIndirectCount = 0x0000000040000000, + DrawIndirectCount = 0x0000000080000000, /// /// All texture compare modes are supported. /// - TextureCompareAll = 0x0000000000300000, + TextureCompareAll = 0x0000000000600000, } [Flags] diff --git a/bindings/d/package.d b/bindings/d/package.d index d87c830587..a3e3f8aaaa 100644 --- a/bindings/d/package.d +++ b/bindings/d/package.d @@ -10,7 +10,7 @@ import bindbc.bgfx.config; import bindbc.common.types: c_int64, c_uint64, va_list; static import bgfx.fakeenum; -enum uint apiVersion = 124; +enum uint apiVersion = 125; alias ViewID = ushort; @@ -499,31 +499,32 @@ enum CapFlags: CapFlags_{ drawIndirect = 0x0000_0000_0000_0010, ///Draw indirect is supported. fragmentDepth = 0x0000_0000_0000_0020, ///Fragment depth is available in fragment shader. fragmentOrdering = 0x0000_0000_0000_0040, ///Fragment ordering is available in fragment shader. - graphicsDebugger = 0x0000_0000_0000_0080, ///Graphics debugger is present. - hdr10 = 0x0000_0000_0000_0100, ///HDR10 rendering is supported. - hiDPI = 0x0000_0000_0000_0200, ///HiDPI rendering is supported. - imageRW = 0x0000_0000_0000_0400, ///Image Read/Write is supported. - index32 = 0x0000_0000_0000_0800, ///32-bit indices are supported. - instancing = 0x0000_0000_0000_1000, ///Instancing is supported. - occlusionQuery = 0x0000_0000_0000_2000, ///Occlusion query is supported. - rendererMultithreaded = 0x0000_0000_0000_4000, ///Renderer is on separate thread. - swapChain = 0x0000_0000_0000_8000, ///Multiple windows are supported. - texture2DArray = 0x0000_0000_0001_0000, ///2D texture array is supported. - texture3D = 0x0000_0000_0002_0000, ///3D textures are supported. - textureBlit = 0x0000_0000_0004_0000, ///Texture blit is supported. - transparentBackbuffer = 0x0000_0000_0008_0000, ///Transparent back buffer supported. - textureCompareReserved = 0x0000_0000_0010_0000, - textureCompareLEqual = 0x0000_0000_0020_0000, ///Texture compare less equal mode is supported. - textureCubeArray = 0x0000_0000_0040_0000, ///Cubemap texture array is supported. - textureDirectAccess = 0x0000_0000_0080_0000, ///CPU direct access to GPU texture memory. - textureReadBack = 0x0000_0000_0100_0000, ///Read-back texture is supported. - vertexAttribHalf = 0x0000_0000_0200_0000, ///Vertex attribute half-float is supported. - vertexAttribUint10 = 0x0000_0000_0400_0000, ///Vertex attribute 10_10_10_2 is supported. - vertexID = 0x0000_0000_0800_0000, ///Rendering with VertexID only is supported. - primitiveID = 0x0000_0000_1000_0000, ///PrimitiveID is available in fragment shader. - viewportLayerArray = 0x0000_0000_2000_0000, ///Viewport layer is available in vertex shader. - drawIndirectCount = 0x0000_0000_4000_0000, ///Draw indirect with indirect count is supported. - textureCompareAll = 0x0000_0000_0030_0000, ///All texture compare modes are supported. + fragmentBarycentric = 0x0000_0000_0000_0080, ///Fragment barycentric coordinates are available in fragment shader. + graphicsDebugger = 0x0000_0000_0000_0100, ///Graphics debugger is present. + hdr10 = 0x0000_0000_0000_0200, ///HDR10 rendering is supported. + hiDPI = 0x0000_0000_0000_0400, ///HiDPI rendering is supported. + imageRW = 0x0000_0000_0000_0800, ///Image Read/Write is supported. + index32 = 0x0000_0000_0000_1000, ///32-bit indices are supported. + instancing = 0x0000_0000_0000_2000, ///Instancing is supported. + occlusionQuery = 0x0000_0000_0000_4000, ///Occlusion query is supported. + rendererMultithreaded = 0x0000_0000_0000_8000, ///Renderer is on separate thread. + swapChain = 0x0000_0000_0001_0000, ///Multiple windows are supported. + texture2DArray = 0x0000_0000_0002_0000, ///2D texture array is supported. + texture3D = 0x0000_0000_0004_0000, ///3D textures are supported. + textureBlit = 0x0000_0000_0008_0000, ///Texture blit is supported. + transparentBackbuffer = 0x0000_0000_0010_0000, ///Transparent back buffer supported. + textureCompareReserved = 0x0000_0000_0020_0000, + textureCompareLEqual = 0x0000_0000_0040_0000, ///Texture compare less equal mode is supported. + textureCubeArray = 0x0000_0000_0080_0000, ///Cubemap texture array is supported. + textureDirectAccess = 0x0000_0000_0100_0000, ///CPU direct access to GPU texture memory. + textureReadBack = 0x0000_0000_0200_0000, ///Read-back texture is supported. + vertexAttribHalf = 0x0000_0000_0400_0000, ///Vertex attribute half-float is supported. + vertexAttribUint10 = 0x0000_0000_0800_0000, ///Vertex attribute 10_10_10_2 is supported. + vertexID = 0x0000_0000_1000_0000, ///Rendering with VertexID only is supported. + primitiveID = 0x0000_0000_2000_0000, ///PrimitiveID is available in fragment shader. + viewportLayerArray = 0x0000_0000_4000_0000, ///Viewport layer is available in vertex shader. + drawIndirectCount = 0x0000_0000_8000_0000, ///Draw indirect with indirect count is supported. + textureCompareAll = 0x0000_0000_0060_0000, ///All texture compare modes are supported. } alias CapsFormat_ = uint; diff --git a/bindings/zig/bgfx.zig b/bindings/zig/bgfx.zig index 9f09d94098..780e942ce0 100644 --- a/bindings/zig/bgfx.zig +++ b/bindings/zig/bgfx.zig @@ -647,78 +647,81 @@ pub const CapsFlags_FragmentDepth: CapsFlags = 0x0000000000000020; /// Fragment ordering is available in fragment shader. pub const CapsFlags_FragmentOrdering: CapsFlags = 0x0000000000000040; +/// Fragment barycentric coordinates are available in fragment shader. +pub const CapsFlags_FragmentBarycentric: CapsFlags = 0x0000000000000080; + /// Graphics debugger is present. -pub const CapsFlags_GraphicsDebugger: CapsFlags = 0x0000000000000080; +pub const CapsFlags_GraphicsDebugger: CapsFlags = 0x0000000000000100; /// HDR10 rendering is supported. -pub const CapsFlags_Hdr10: CapsFlags = 0x0000000000000100; +pub const CapsFlags_Hdr10: CapsFlags = 0x0000000000000200; /// HiDPI rendering is supported. -pub const CapsFlags_Hidpi: CapsFlags = 0x0000000000000200; +pub const CapsFlags_Hidpi: CapsFlags = 0x0000000000000400; /// Image Read/Write is supported. -pub const CapsFlags_ImageRw: CapsFlags = 0x0000000000000400; +pub const CapsFlags_ImageRw: CapsFlags = 0x0000000000000800; /// 32-bit indices are supported. -pub const CapsFlags_Index32: CapsFlags = 0x0000000000000800; +pub const CapsFlags_Index32: CapsFlags = 0x0000000000001000; /// Instancing is supported. -pub const CapsFlags_Instancing: CapsFlags = 0x0000000000001000; +pub const CapsFlags_Instancing: CapsFlags = 0x0000000000002000; /// Occlusion query is supported. -pub const CapsFlags_OcclusionQuery: CapsFlags = 0x0000000000002000; +pub const CapsFlags_OcclusionQuery: CapsFlags = 0x0000000000004000; /// Renderer is on separate thread. -pub const CapsFlags_RendererMultithreaded: CapsFlags = 0x0000000000004000; +pub const CapsFlags_RendererMultithreaded: CapsFlags = 0x0000000000008000; /// Multiple windows are supported. -pub const CapsFlags_SwapChain: CapsFlags = 0x0000000000008000; +pub const CapsFlags_SwapChain: CapsFlags = 0x0000000000010000; /// 2D texture array is supported. -pub const CapsFlags_Texture2DArray: CapsFlags = 0x0000000000010000; +pub const CapsFlags_Texture2DArray: CapsFlags = 0x0000000000020000; /// 3D textures are supported. -pub const CapsFlags_Texture3D: CapsFlags = 0x0000000000020000; +pub const CapsFlags_Texture3D: CapsFlags = 0x0000000000040000; /// Texture blit is supported. -pub const CapsFlags_TextureBlit: CapsFlags = 0x0000000000040000; +pub const CapsFlags_TextureBlit: CapsFlags = 0x0000000000080000; /// Transparent back buffer supported. -pub const CapsFlags_TransparentBackbuffer: CapsFlags = 0x0000000000080000; -pub const CapsFlags_TextureCompareReserved: CapsFlags = 0x0000000000100000; +pub const CapsFlags_TransparentBackbuffer: CapsFlags = 0x0000000000100000; +pub const CapsFlags_TextureCompareReserved: CapsFlags = 0x0000000000200000; /// Texture compare less equal mode is supported. -pub const CapsFlags_TextureCompareLequal: CapsFlags = 0x0000000000200000; +pub const CapsFlags_TextureCompareLequal: CapsFlags = 0x0000000000400000; /// Cubemap texture array is supported. -pub const CapsFlags_TextureCubeArray: CapsFlags = 0x0000000000400000; +pub const CapsFlags_TextureCubeArray: CapsFlags = 0x0000000000800000; /// CPU direct access to GPU texture memory. -pub const CapsFlags_TextureDirectAccess: CapsFlags = 0x0000000000800000; +pub const CapsFlags_TextureDirectAccess: CapsFlags = 0x0000000001000000; /// Read-back texture is supported. -pub const CapsFlags_TextureReadBack: CapsFlags = 0x0000000001000000; +pub const CapsFlags_TextureReadBack: CapsFlags = 0x0000000002000000; /// Vertex attribute half-float is supported. -pub const CapsFlags_VertexAttribHalf: CapsFlags = 0x0000000002000000; +pub const CapsFlags_VertexAttribHalf: CapsFlags = 0x0000000004000000; /// Vertex attribute 10_10_10_2 is supported. -pub const CapsFlags_VertexAttribUint10: CapsFlags = 0x0000000004000000; +pub const CapsFlags_VertexAttribUint10: CapsFlags = 0x0000000008000000; /// Rendering with VertexID only is supported. -pub const CapsFlags_VertexId: CapsFlags = 0x0000000008000000; +pub const CapsFlags_VertexId: CapsFlags = 0x0000000010000000; /// PrimitiveID is available in fragment shader. -pub const CapsFlags_PrimitiveId: CapsFlags = 0x0000000010000000; +pub const CapsFlags_PrimitiveId: CapsFlags = 0x0000000020000000; /// Viewport layer is available in vertex shader. -pub const CapsFlags_ViewportLayerArray: CapsFlags = 0x0000000020000000; +pub const CapsFlags_ViewportLayerArray: CapsFlags = 0x0000000040000000; /// Draw indirect with indirect count is supported. -pub const CapsFlags_DrawIndirectCount: CapsFlags = 0x0000000040000000; +pub const CapsFlags_DrawIndirectCount: CapsFlags = 0x0000000080000000; /// All texture compare modes are supported. -pub const CapsFlags_TextureCompareAll: CapsFlags = 0x0000000000300000; +pub const CapsFlags_TextureCompareAll: CapsFlags = 0x0000000000600000; pub const CapsFormatFlags = u32; /// Texture format is not supported. diff --git a/examples/28-wireframe/fs_wf_mesh_bc.sc b/examples/28-wireframe/fs_wf_mesh_bc.sc new file mode 100644 index 0000000000..ec743cffe6 --- /dev/null +++ b/examples/28-wireframe/fs_wf_mesh_bc.sc @@ -0,0 +1,79 @@ +$input v_view, v_normal + +/* + * Copyright 2016 Dario Manesku. All rights reserved. + * License: https://github.com/bkaradzic/bgfx/blob/master/LICENSE + */ + +#include "../common/common.sh" +#include "uniforms.sh" + +vec3 evalSh(vec3 _dir) +{ +# define k01 0.2820947918 // sqrt( 1/PI)/2 +# define k02 0.4886025119 // sqrt( 3/PI)/2 +# define k03 1.0925484306 // sqrt(15/PI)/2 +# define k04 0.3153915652 // sqrt( 5/PI)/4 +# define k05 0.5462742153 // sqrt(15/PI)/4 + + vec3 shEnv[9]; + shEnv[0] = vec3( 0.967757057878229854, 0.976516067990363390, 0.891218272348969998); /* Band 0 */ + shEnv[1] = vec3(-0.384163503608655643, -0.423492289131209787, -0.425532726148547868); /* Band 1 */ + shEnv[2] = vec3( 0.055906294587354334, 0.056627436881069373, 0.069969936396987467); + shEnv[3] = vec3( 0.120985157386215209, 0.119297994074027414, 0.117111965829213599); + shEnv[4] = vec3(-0.176711633774331106, -0.170331404095516392, -0.151345020570876621); /* Band 2 */ + shEnv[5] = vec3(-0.124682114349692147, -0.119340785411183953, -0.096300354204368860); + shEnv[6] = vec3( 0.001852378550138503, -0.032592784164597745, -0.088204495001329680); + shEnv[7] = vec3( 0.296365482782109446, 0.281268696656263029, 0.243328223888495510); + shEnv[8] = vec3(-0.079826665303240341, -0.109340956251195970, -0.157208859664677764); + + vec3 nn = _dir.zxy; + + float sh[9]; + sh[0] = k01; + sh[1] = -k02*nn.y; + sh[2] = k02*nn.z; + sh[3] = -k02*nn.x; + sh[4] = k03*nn.y*nn.x; + sh[5] = -k03*nn.y*nn.z; + sh[6] = k04*(3.0*nn.z*nn.z-1.0); + sh[7] = -k03*nn.x*nn.z; + sh[8] = k05*(nn.x*nn.x-nn.y*nn.y); + + vec3 rgb = vec3_splat(0.0); + rgb += shEnv[0] * sh[0] * 1.0; + rgb += shEnv[1] * sh[1] * 2.0/2.5; + rgb += shEnv[2] * sh[2] * 2.0/2.5; + rgb += shEnv[3] * sh[3] * 2.0/2.5; + rgb += shEnv[4] * sh[4] * 1.0/2.5; + rgb += shEnv[5] * sh[5] * 0.5; + rgb += shEnv[6] * sh[6] * 0.5; + rgb += shEnv[7] * sh[7] * 0.5; + rgb += shEnv[8] * sh[8] * 0.5; + + return rgb; +} + +void main() +{ + vec3 nn = normalize(v_normal); + vec3 col = evalSh(nn); + + if (0.0 != u_drawEdges) + { + vec3 wfColor = u_wfColor; + float wfOpacity = u_wfOpacity; + float thickness = u_wfThickness; + + vec3 bc = gl_BaryCoord; + vec3 fw = abs(dFdx(bc)) + abs(dFdy(bc)); + vec3 val = smoothstep(vec3_splat(0.0), fw*thickness, bc); + float edge = min(min(val.x, val.y), val.z); // Gets to 0.0 when close to edges. + + vec3 edgeCol = mix(col, wfColor, wfOpacity); + col = mix(edgeCol, col, edge); + } + + gl_FragColor.xyz = col; + gl_FragColor.w = 1.0; +} diff --git a/examples/28-wireframe/fs_wf_wireframe_bc.sc b/examples/28-wireframe/fs_wf_wireframe_bc.sc new file mode 100644 index 0000000000..0b9258392c --- /dev/null +++ b/examples/28-wireframe/fs_wf_wireframe_bc.sc @@ -0,0 +1,27 @@ +$input v_view + +/* + * Copyright 2016 Dario Manesku. All rights reserved. + * License: https://github.com/bkaradzic/bgfx/blob/master/LICENSE + */ + +#include "../common/common.sh" +#include "uniforms.sh" + +void main() +{ + vec3 color = u_wfColor; + float opacity = u_wfOpacity; + float thickness = u_wfThickness; + + if (gl_FrontFacing) { opacity *= 0.5; } + + vec3 bc = gl_BaryCoord; + vec3 fw = abs(dFdx(bc)) + abs(dFdy(bc)); + vec3 val = smoothstep(vec3_splat(0.0), fw*thickness, bc); + float edge = min(min(val.x, val.y), val.z); // Gets to 0.0 around the edges. + + vec4 rgba = vec4(color, (1.0-edge)*opacity); + gl_FragColor = rgba; +} + diff --git a/examples/28-wireframe/vs_wf_mesh_bc.sc b/examples/28-wireframe/vs_wf_mesh_bc.sc new file mode 100644 index 0000000000..7189543e0e --- /dev/null +++ b/examples/28-wireframe/vs_wf_mesh_bc.sc @@ -0,0 +1,20 @@ +$input a_position, a_normal +$output v_view, v_normal + +/* + * Copyright 2016 Dario Manesku. All rights reserved. + * License: https://github.com/bkaradzic/bgfx/blob/master/LICENSE + */ + +#include "../common/common.sh" +#include "uniforms.sh" + +void main() +{ + gl_Position = mul(u_modelViewProj, vec4(a_position, 1.0) ); + + v_view = u_camPos - mul(u_model[0], vec4(a_position, 1.0) ).xyz; + + vec3 normal = a_normal.xyz*2.0 - 1.0; + v_normal = mul(u_model[0], vec4(normal, 0.0) ).xyz; +} diff --git a/examples/28-wireframe/vs_wf_wireframe_bc.sc b/examples/28-wireframe/vs_wf_wireframe_bc.sc new file mode 100644 index 0000000000..1d10ced57d --- /dev/null +++ b/examples/28-wireframe/vs_wf_wireframe_bc.sc @@ -0,0 +1,18 @@ +$input a_position +$output v_view + +/* + * Copyright 2016 Dario Manesku. All rights reserved. + * License: https://github.com/bkaradzic/bgfx/blob/master/LICENSE + */ + +#include "../common/common.sh" +#include "uniforms.sh" + +void main() +{ + gl_Position = mul(u_modelViewProj, vec4(a_position, 1.0) ); + + v_view = u_camPos - mul(u_model[0], vec4(a_position, 1.0) ).xyz; +} + diff --git a/examples/28-wireframe/wireframe.cpp b/examples/28-wireframe/wireframe.cpp index 75001cda52..cc2c99d755 100644 --- a/examples/28-wireframe/wireframe.cpp +++ b/examples/28-wireframe/wireframe.cpp @@ -6,6 +6,7 @@ #include "common.h" #include "bgfx_utils.h" #include "imgui/imgui.h" +#include "entry/dialog.h" namespace { @@ -299,6 +300,8 @@ class ExampleWireframe : public entry::AppI init.resolution.reset = m_reset; bgfx::init(init); + m_hasBaryCoord = bgfx::getCaps()->supported & BGFX_CAPS_FRAGMENT_BARYCENTRIC; + // Enable m_debug text. bgfx::setDebug(m_debug); @@ -310,6 +313,11 @@ class ExampleWireframe : public entry::AppI , 0 ); + if (m_hasBaryCoord) + { + m_wfProgramBc = loadProgram("vs_wf_wireframe_bc", "fs_wf_wireframe_bc"); + m_meshProgramBc = loadProgram("vs_wf_mesh_bc", "fs_wf_mesh_bc"); + } m_wfProgram = loadProgram("vs_wf_wireframe", "fs_wf_wireframe"); m_meshProgram = loadProgram("vs_wf_mesh", "fs_wf_mesh"); @@ -339,6 +347,11 @@ class ExampleWireframe : public entry::AppI m_meshes[1].destroy(); m_meshes[2].destroy(); + if (m_hasBaryCoord) + { + bgfx::destroy(m_wfProgramBc); + bgfx::destroy(m_meshProgramBc); + } bgfx::destroy(m_wfProgram); bgfx::destroy(m_meshProgram); @@ -395,6 +408,35 @@ class ExampleWireframe : public entry::AppI ImGui::RadioButton("Wireframe", &m_drawMode, 1); ImGui::RadioButton("Shaded", &m_drawMode, 2); + static bool wfBaryCoordEnabled = false; + if (!m_hasBaryCoord) + { + ImGui::BeginDisabled(); + } + + ImGui::Separator(); + + ImGui::Checkbox("Shader barycentric coords", &wfBaryCoordEnabled); + + if (!m_hasBaryCoord) + { + ImGui::EndDisabled(); + + static const bx::StringView url = R"(https://vulkan.gpuinfo.org/listdevicescoverage.php?extensionname=VK_KHR_fragment_shader_barycentric&extensionfeature=fragmentShaderBarycentric&platform=all)"; + + ImGui::TextWrapped("Your GPU/backend doesn't support this feature yet."); + ImGui::TextWrapped("For a list of supported GPUs please click below:"); + + if (ImGui::SmallButton(ICON_FA_LINK) ) + { + openUrl(url); + } + else if (ImGui::IsItemHovered() ) + { + ImGui::SetTooltip("%.*s", url.getLength(), url.getPtr() ); + } + } + const bool wfEnabled = (DrawMode::Shaded != m_drawMode); if ( wfEnabled ) { @@ -475,7 +517,22 @@ class ExampleWireframe : public entry::AppI | BGFX_STATE_MSAA | BGFX_STATE_BLEND_FUNC(BGFX_STATE_BLEND_SRC_ALPHA, BGFX_STATE_BLEND_INV_SRC_ALPHA) ; - meshSubmit(m_meshes[m_meshSelection].m_mesh, 0, m_wfProgram, m_meshes[m_meshSelection].m_mtx, state); + if (wfBaryCoordEnabled && m_hasBaryCoord) + { + meshSubmit(m_meshes[m_meshSelection].m_mesh, + 0, + m_wfProgramBc, + m_meshes[m_meshSelection].m_mtx, + state); + } + else + { + meshSubmit(m_meshes[m_meshSelection].m_mesh, + 0, + m_wfProgram, + m_meshes[m_meshSelection].m_mtx, + state); + } } else { @@ -487,7 +544,22 @@ class ExampleWireframe : public entry::AppI | BGFX_STATE_CULL_CCW | BGFX_STATE_MSAA ; - meshSubmit(m_meshes[m_meshSelection].m_mesh, 0, m_meshProgram, m_meshes[m_meshSelection].m_mtx, state); + if (wfBaryCoordEnabled && m_hasBaryCoord) + { + meshSubmit(m_meshes[m_meshSelection].m_mesh, + 0, + m_meshProgramBc, + m_meshes[m_meshSelection].m_mtx, + state); + } + else + { + meshSubmit(m_meshes[m_meshSelection].m_mesh, + 0, + m_meshProgram, + m_meshes[m_meshSelection].m_mtx, + state); + } } // Advance to next frame. Rendering thread will be kicked to @@ -502,6 +574,8 @@ class ExampleWireframe : public entry::AppI entry::MouseState m_mouseState; + bgfx::ProgramHandle m_wfProgramBc; + bgfx::ProgramHandle m_meshProgramBc; bgfx::ProgramHandle m_wfProgram; bgfx::ProgramHandle m_meshProgram; @@ -520,6 +594,7 @@ class ExampleWireframe : public entry::AppI MeshMtx m_meshes[3]; int32_t m_meshSelection; int32_t m_drawMode; // Holds data for 'DrawMode'. + bool m_hasBaryCoord; }; } // namespace diff --git a/include/bgfx/defines.h b/include/bgfx/defines.h index da57615a3a..f51c0f93cc 100644 --- a/include/bgfx/defines.h +++ b/include/bgfx/defines.h @@ -15,7 +15,7 @@ #ifndef BGFX_DEFINES_H_HEADER_GUARD #define BGFX_DEFINES_H_HEADER_GUARD -#define BGFX_API_VERSION UINT32_C(124) +#define BGFX_API_VERSION UINT32_C(125) /** * Color RGB/alpha/depth write. When it's not specified write will be disabled. @@ -469,30 +469,31 @@ #define BGFX_CAPS_DRAW_INDIRECT UINT64_C(0x0000000000000010) //!< Draw indirect is supported. #define BGFX_CAPS_FRAGMENT_DEPTH UINT64_C(0x0000000000000020) //!< Fragment depth is available in fragment shader. #define BGFX_CAPS_FRAGMENT_ORDERING UINT64_C(0x0000000000000040) //!< Fragment ordering is available in fragment shader. -#define BGFX_CAPS_GRAPHICS_DEBUGGER UINT64_C(0x0000000000000080) //!< Graphics debugger is present. -#define BGFX_CAPS_HDR10 UINT64_C(0x0000000000000100) //!< HDR10 rendering is supported. -#define BGFX_CAPS_HIDPI UINT64_C(0x0000000000000200) //!< HiDPI rendering is supported. -#define BGFX_CAPS_IMAGE_RW UINT64_C(0x0000000000000400) //!< Image Read/Write is supported. -#define BGFX_CAPS_INDEX32 UINT64_C(0x0000000000000800) //!< 32-bit indices are supported. -#define BGFX_CAPS_INSTANCING UINT64_C(0x0000000000001000) //!< Instancing is supported. -#define BGFX_CAPS_OCCLUSION_QUERY UINT64_C(0x0000000000002000) //!< Occlusion query is supported. -#define BGFX_CAPS_RENDERER_MULTITHREADED UINT64_C(0x0000000000004000) //!< Renderer is on separate thread. -#define BGFX_CAPS_SWAP_CHAIN UINT64_C(0x0000000000008000) //!< Multiple windows are supported. -#define BGFX_CAPS_TEXTURE_2D_ARRAY UINT64_C(0x0000000000010000) //!< 2D texture array is supported. -#define BGFX_CAPS_TEXTURE_3D UINT64_C(0x0000000000020000) //!< 3D textures are supported. -#define BGFX_CAPS_TEXTURE_BLIT UINT64_C(0x0000000000040000) //!< Texture blit is supported. -#define BGFX_CAPS_TRANSPARENT_BACKBUFFER UINT64_C(0x0000000000080000) //!< Transparent back buffer supported. -#define BGFX_CAPS_TEXTURE_COMPARE_RESERVED UINT64_C(0x0000000000100000) -#define BGFX_CAPS_TEXTURE_COMPARE_LEQUAL UINT64_C(0x0000000000200000) //!< Texture compare less equal mode is supported. -#define BGFX_CAPS_TEXTURE_CUBE_ARRAY UINT64_C(0x0000000000400000) //!< Cubemap texture array is supported. -#define BGFX_CAPS_TEXTURE_DIRECT_ACCESS UINT64_C(0x0000000000800000) //!< CPU direct access to GPU texture memory. -#define BGFX_CAPS_TEXTURE_READ_BACK UINT64_C(0x0000000001000000) //!< Read-back texture is supported. -#define BGFX_CAPS_VERTEX_ATTRIB_HALF UINT64_C(0x0000000002000000) //!< Vertex attribute half-float is supported. -#define BGFX_CAPS_VERTEX_ATTRIB_UINT10 UINT64_C(0x0000000004000000) //!< Vertex attribute 10_10_10_2 is supported. -#define BGFX_CAPS_VERTEX_ID UINT64_C(0x0000000008000000) //!< Rendering with VertexID only is supported. -#define BGFX_CAPS_PRIMITIVE_ID UINT64_C(0x0000000010000000) //!< PrimitiveID is available in fragment shader. -#define BGFX_CAPS_VIEWPORT_LAYER_ARRAY UINT64_C(0x0000000020000000) //!< Viewport layer is available in vertex shader. -#define BGFX_CAPS_DRAW_INDIRECT_COUNT UINT64_C(0x0000000040000000) //!< Draw indirect with indirect count is supported. +#define BGFX_CAPS_FRAGMENT_BARYCENTRIC UINT64_C(0x0000000000000080) //!< Fragment barycentric coordinates are available in fragment shader. +#define BGFX_CAPS_GRAPHICS_DEBUGGER UINT64_C(0x0000000000000100) //!< Graphics debugger is present. +#define BGFX_CAPS_HDR10 UINT64_C(0x0000000000000200) //!< HDR10 rendering is supported. +#define BGFX_CAPS_HIDPI UINT64_C(0x0000000000000400) //!< HiDPI rendering is supported. +#define BGFX_CAPS_IMAGE_RW UINT64_C(0x0000000000000800) //!< Image Read/Write is supported. +#define BGFX_CAPS_INDEX32 UINT64_C(0x0000000000001000) //!< 32-bit indices are supported. +#define BGFX_CAPS_INSTANCING UINT64_C(0x0000000000002000) //!< Instancing is supported. +#define BGFX_CAPS_OCCLUSION_QUERY UINT64_C(0x0000000000004000) //!< Occlusion query is supported. +#define BGFX_CAPS_RENDERER_MULTITHREADED UINT64_C(0x0000000000008000) //!< Renderer is on separate thread. +#define BGFX_CAPS_SWAP_CHAIN UINT64_C(0x0000000000010000) //!< Multiple windows are supported. +#define BGFX_CAPS_TEXTURE_2D_ARRAY UINT64_C(0x0000000000020000) //!< 2D texture array is supported. +#define BGFX_CAPS_TEXTURE_3D UINT64_C(0x0000000000040000) //!< 3D textures are supported. +#define BGFX_CAPS_TEXTURE_BLIT UINT64_C(0x0000000000080000) //!< Texture blit is supported. +#define BGFX_CAPS_TRANSPARENT_BACKBUFFER UINT64_C(0x0000000000100000) //!< Transparent back buffer supported. +#define BGFX_CAPS_TEXTURE_COMPARE_RESERVED UINT64_C(0x0000000000200000) +#define BGFX_CAPS_TEXTURE_COMPARE_LEQUAL UINT64_C(0x0000000000400000) //!< Texture compare less equal mode is supported. +#define BGFX_CAPS_TEXTURE_CUBE_ARRAY UINT64_C(0x0000000000800000) //!< Cubemap texture array is supported. +#define BGFX_CAPS_TEXTURE_DIRECT_ACCESS UINT64_C(0x0000000001000000) //!< CPU direct access to GPU texture memory. +#define BGFX_CAPS_TEXTURE_READ_BACK UINT64_C(0x0000000002000000) //!< Read-back texture is supported. +#define BGFX_CAPS_VERTEX_ATTRIB_HALF UINT64_C(0x0000000004000000) //!< Vertex attribute half-float is supported. +#define BGFX_CAPS_VERTEX_ATTRIB_UINT10 UINT64_C(0x0000000008000000) //!< Vertex attribute 10_10_10_2 is supported. +#define BGFX_CAPS_VERTEX_ID UINT64_C(0x0000000010000000) //!< Rendering with VertexID only is supported. +#define BGFX_CAPS_PRIMITIVE_ID UINT64_C(0x0000000020000000) //!< PrimitiveID is available in fragment shader. +#define BGFX_CAPS_VIEWPORT_LAYER_ARRAY UINT64_C(0x0000000040000000) //!< Viewport layer is available in vertex shader. +#define BGFX_CAPS_DRAW_INDIRECT_COUNT UINT64_C(0x0000000080000000) //!< Draw indirect with indirect count is supported. /// All texture compare modes are supported. #define BGFX_CAPS_TEXTURE_COMPARE_ALL (0 \ | BGFX_CAPS_TEXTURE_COMPARE_RESERVED \ diff --git a/scripts/bgfx.idl b/scripts/bgfx.idl index 189645c7cc..ed5b94c75e 100644 --- a/scripts/bgfx.idl +++ b/scripts/bgfx.idl @@ -1,7 +1,7 @@ -- vim: syntax=lua -- bgfx interface -version(124) +version(125) typedef "bool" typedef "char" @@ -372,6 +372,7 @@ flag.Caps { bits = 64, base = 1, name = "Caps" } .DrawIndirect --- Draw indirect is supported. .FragmentDepth --- Fragment depth is available in fragment shader. .FragmentOrdering --- Fragment ordering is available in fragment shader. + .FragmentBarycentric --- Fragment barycentric coordinates are available in fragment shader. .GraphicsDebugger --- Graphics debugger is present. .Hdr10 --- HDR10 rendering is supported. .Hidpi --- HiDPI rendering is supported. diff --git a/src/bgfx.cpp b/src/bgfx.cpp index d11152c54b..d2f2a79e30 100644 --- a/src/bgfx.cpp +++ b/src/bgfx.cpp @@ -1573,6 +1573,7 @@ namespace bgfx CAPS_FLAGS(BGFX_CAPS_VERTEX_ID), CAPS_FLAGS(BGFX_CAPS_PRIMITIVE_ID), CAPS_FLAGS(BGFX_CAPS_VIEWPORT_LAYER_ARRAY), + CAPS_FLAGS(BGFX_CAPS_FRAGMENT_BARYCENTRIC), #undef CAPS_FLAGS }; @@ -5785,6 +5786,7 @@ BX_STATIC_ASSERT( (0 | BGFX_CAPS_PRIMITIVE_ID | BGFX_CAPS_VIEWPORT_LAYER_ARRAY | BGFX_CAPS_DRAW_INDIRECT_COUNT + | BGFX_CAPS_FRAGMENT_BARYCENTRIC ) == (0 ^ BGFX_CAPS_ALPHA_TO_COVERAGE ^ BGFX_CAPS_BLEND_INDEPENDENT @@ -5813,6 +5815,7 @@ BX_STATIC_ASSERT( (0 ^ BGFX_CAPS_PRIMITIVE_ID ^ BGFX_CAPS_VIEWPORT_LAYER_ARRAY ^ BGFX_CAPS_DRAW_INDIRECT_COUNT + ^ BGFX_CAPS_FRAGMENT_BARYCENTRIC ) ); #undef FLAGS_MASK_TEST diff --git a/src/renderer_d3d12.cpp b/src/renderer_d3d12.cpp index 334e336a79..cf2aae102a 100644 --- a/src/renderer_d3d12.cpp +++ b/src/renderer_d3d12.cpp @@ -975,6 +975,7 @@ namespace bgfx { namespace d3d12 } DX_CHECK(m_device->CheckFeatureSupport(D3D12_FEATURE_D3D12_OPTIONS, &m_options, sizeof(m_options) ) ); + //DX_CHECK(m_device->CheckFeatureSupport(D3D12_FEATURE_D3D12_OPTIONS3, &m_options3, sizeof(m_options3) ) ); BX_TRACE("D3D12 options:"); BX_TRACE("\tTiledResourcesTier %d", m_options.TiledResourcesTier); BX_TRACE("\tResourceBindingTier %d", m_options.ResourceBindingTier); @@ -982,6 +983,7 @@ namespace bgfx { namespace d3d12 BX_TRACE("\tConservativeRasterizationTier %d", m_options.ConservativeRasterizationTier); BX_TRACE("\tCrossNodeSharingTier %d", m_options.CrossNodeSharingTier); BX_TRACE("\tResourceHeapTier %d", m_options.ResourceHeapTier); + //BX_TRACE("\tBarycentricsSupported %d", m_options3.BarycentricsSupported); for (D3D12_FEATURE_DATA_D3D12_OPTIONS1 options1; SUCCEEDED(m_device->CheckFeatureSupport(D3D12_FEATURE_D3D12_OPTIONS1, &options1, sizeof(options1)));) { @@ -1366,6 +1368,7 @@ namespace bgfx { namespace d3d12 | BGFX_CAPS_VIEWPORT_LAYER_ARRAY | BGFX_CAPS_DRAW_INDIRECT_COUNT | BGFX_CAPS_PRIMITIVE_ID + //| (m_options3.BarycentricsSupported ? BGFX_CAPS_FRAGMENT_BARYCENTRIC : 0) ); g_caps.limits.maxTextureSize = D3D12_REQ_TEXTURE2D_U_OR_V_DIMENSION; g_caps.limits.maxTextureLayers = D3D12_REQ_TEXTURE2D_ARRAY_AXIS_DIMENSION; @@ -3573,6 +3576,7 @@ namespace bgfx { namespace d3d12 D3D_DRIVER_TYPE m_driverType; D3D12_FEATURE_DATA_ARCHITECTURE m_architecture; D3D12_FEATURE_DATA_D3D12_OPTIONS m_options; + //D3D12_FEATURE_DATA_D3D12_OPTIONS3 m_options3; Dxgi::SwapChainI* m_swapChain; ID3D12Resource* m_msaaRt; diff --git a/src/renderer_gl.cpp b/src/renderer_gl.cpp index 92c8235cd3..636ffb2cf8 100644 --- a/src/renderer_gl.cpp +++ b/src/renderer_gl.cpp @@ -623,6 +623,7 @@ namespace bgfx { namespace gl EXT_draw_instanced, EXT_instanced_arrays, EXT_frag_depth, + EXT_fragment_shader_barycentric, EXT_framebuffer_blit, EXT_framebuffer_object, EXT_framebuffer_sRGB, @@ -676,6 +677,7 @@ namespace bgfx { namespace gl NV_copy_image, NV_draw_buffers, NV_draw_instanced, + NV_fragment_shader_barycentric, NV_instanced_arrays, NV_occlusion_query, NV_texture_border_clamp, @@ -841,6 +843,7 @@ namespace bgfx { namespace gl { "EXT_draw_instanced", false, true }, // GLES2 extension. { "EXT_instanced_arrays", false, true }, // GLES2 extension. { "EXT_frag_depth", false, true }, // GLES2 extension. + { "EXT_fragment_shader_barycentric", BGFX_CONFIG_RENDERER_OPENGL >= 46, true }, { "EXT_framebuffer_blit", BGFX_CONFIG_RENDERER_OPENGL >= 30, true }, { "EXT_framebuffer_object", BGFX_CONFIG_RENDERER_OPENGL >= 30, true }, { "EXT_framebuffer_sRGB", BGFX_CONFIG_RENDERER_OPENGL >= 30, true }, @@ -894,6 +897,7 @@ namespace bgfx { namespace gl { "NV_copy_image", false, true }, { "NV_draw_buffers", false, true }, // GLES2 extension. { "NV_draw_instanced", false, true }, // GLES2 extension. + { "NV_fragment_shader_barycentric", BGFX_CONFIG_RENDERER_OPENGL >= 46, true }, { "NV_instanced_arrays", false, true }, // GLES2 extension. { "NV_occlusion_query", false, true }, { "NV_texture_border_clamp", false, true }, // GLES2 extension. @@ -1083,6 +1087,13 @@ namespace bgfx { namespace gl NULL }; + static const char* s_EXT_fragment_shader_barycentric[] = + { + "gl_BaryCoord", + "gl_BaryCoordNoPersp", + NULL + }; + static void GL_APIENTRY stubVertexAttribDivisor(GLuint /*_index*/, GLuint /*_divisor*/) { } @@ -2824,6 +2835,12 @@ namespace bgfx { namespace gl ? BGFX_CAPS_FRAGMENT_ORDERING : 0 ; + g_caps.supported |= false + || s_extension[Extension::EXT_fragment_shader_barycentric].m_supported + || s_extension[Extension::NV_fragment_shader_barycentric].m_supported + ? BGFX_CAPS_FRAGMENT_BARYCENTRIC + : 0 + ; g_caps.supported |= !!(BGFX_CONFIG_RENDERER_OPENGL || m_gles3) || s_extension[Extension::OES_element_index_uint].m_supported ? BGFX_CAPS_INDEX32 @@ -6855,6 +6872,47 @@ namespace bgfx { namespace gl code = temp; } + else if (GL_FRAGMENT_SHADER == m_type) + { + if (BX_ENABLED(BGFX_CONFIG_RENDERER_OPENGL >= 46)) + { + int32_t codeLen = (int32_t)bx::strLen(code); + int32_t tempLen = codeLen + (4<<10); + char* temp = (char*)alloca(tempLen); + bx::StaticMemoryBlockWriter writer(temp, tempLen); + + bx::write(&writer + , "#version 460\n" + , &err + ); + + if (!bx::findIdentifierMatch(code, s_EXT_fragment_shader_barycentric).isEmpty()) + { + if (s_extension[Extension::NV_fragment_shader_barycentric].m_supported) + { + bx::write(&writer, + "#extension GL_NV_fragment_shader_barycentric : require\n" + "#define gl_BaryCoord gl_BaryCoordNV\n" + "#define gl_BaryCoordNoPersp gl_BaryCoordNoPerspNV\n", &err + ); + } + else if (s_extension[Extension::EXT_fragment_shader_barycentric].m_supported) + { + bx::write(&writer, + "#extension GL_EXT_fragment_shader_barycentric : require\n" + "#define gl_BaryCoord gl_BaryCoordEXT\n" + "#define gl_BaryCoordNoPersp gl_BaryCoordNoPerspEXT\n", &err + ); + } + } + + int32_t verLen = bx::strLen("#version 460\n"); + bx::write(&writer, code.getPtr()+verLen, codeLen-verLen, &err); + bx::write(&writer, '\0', &err); + + code = temp; + } + } { const GLchar* str = (const GLchar*)code.getPtr(); diff --git a/src/renderer_mtl.h b/src/renderer_mtl.h index e22875a5f9..1041be7879 100644 --- a/src/renderer_mtl.h +++ b/src/renderer_mtl.h @@ -400,6 +400,11 @@ namespace bgfx { namespace mtl return m_obj.depth24Stencil8PixelFormatSupported; #endif // BX_PLATFORM_IOS } + + bool supportsShaderBarycentricCoordinates() + { + return [m_obj supportsShaderBarycentricCoordinates]; + } MTL_CLASS_END MTL_CLASS(Function) diff --git a/src/renderer_mtl.mm b/src/renderer_mtl.mm index 0a7d909e98..d979783905 100644 --- a/src/renderer_mtl.mm +++ b/src/renderer_mtl.mm @@ -636,6 +636,7 @@ bool init(const Init& _init) ? BGFX_CAPS_PRIMITIVE_ID : 0 ; + g_caps.supported |= m_device.supportsShaderBarycentricCoordinates() ? BGFX_CAPS_FRAGMENT_BARYCENTRIC : 0; // Reference(s): // - Metal feature set tables diff --git a/src/renderer_noop.cpp b/src/renderer_noop.cpp index 2c3dc0b2f7..7eb73691ca 100644 --- a/src/renderer_noop.cpp +++ b/src/renderer_noop.cpp @@ -36,6 +36,7 @@ namespace bgfx { namespace noop | BGFX_CAPS_TEXTURE_READ_BACK | BGFX_CAPS_VERTEX_ATTRIB_HALF | BGFX_CAPS_VERTEX_ATTRIB_UINT10 + | BGFX_CAPS_FRAGMENT_BARYCENTRIC ; // Pretend all features are available for all texture formats. diff --git a/src/renderer_vk.cpp b/src/renderer_vk.cpp index e53aec9f0b..26a54fcf3e 100644 --- a/src/renderer_vk.cpp +++ b/src/renderer_vk.cpp @@ -346,6 +346,7 @@ VK_IMPORT_DEVICE EXT_shader_viewport_index_layer, KHR_draw_indirect_count, KHR_get_physical_device_properties2, + KHR_fragment_shader_barycentric, Count }; @@ -371,6 +372,7 @@ VK_IMPORT_DEVICE { "VK_EXT_shader_viewport_index_layer", 1, false, false, true, Layer::Count }, { "VK_KHR_draw_indirect_count", 1, false, false, true, Layer::Count }, { "VK_KHR_get_physical_device_properties2", 1, false, false, true, Layer::Count }, + { "VK_KHR_fragment_shader_barycentric", 1, false, false, true, Layer::Count }, }; BX_STATIC_ASSERT(Extension::Count == BX_COUNTOF(s_extension) ); @@ -1135,9 +1137,11 @@ VK_IMPORT_DEVICE const void* nextFeatures = NULL; VkPhysicalDeviceLineRasterizationFeaturesEXT lineRasterizationFeatures; VkPhysicalDeviceCustomBorderColorFeaturesEXT customBorderColorFeatures; + VkPhysicalDeviceFragmentShaderBarycentricFeaturesKHR fragmentShaderBarycentricFeatures; bx::memSet(&lineRasterizationFeatures, 0, sizeof(lineRasterizationFeatures) ); bx::memSet(&customBorderColorFeatures, 0, sizeof(customBorderColorFeatures) ); + bx::memSet(&fragmentShaderBarycentricFeatures, 0, sizeof(fragmentShaderBarycentricFeatures) ); m_fbh.idx = kInvalidHandle; bx::memSet(m_uniforms, 0, sizeof(m_uniforms) ); @@ -1203,6 +1207,7 @@ VK_IMPORT s_extension[Extension::EXT_shader_viewport_index_layer].m_initialize = !!(_init.capabilities & BGFX_CAPS_VIEWPORT_LAYER_ARRAY); s_extension[Extension::EXT_conservative_rasterization ].m_initialize = !!(_init.capabilities & BGFX_CAPS_CONSERVATIVE_RASTER ); s_extension[Extension::KHR_draw_indirect_count ].m_initialize = !!(_init.capabilities & BGFX_CAPS_DRAW_INDIRECT_COUNT ); + s_extension[Extension::KHR_fragment_shader_barycentric].m_initialize = !!(_init.capabilities & BGFX_CAPS_FRAGMENT_BARYCENTRIC); dumpExtensions(VK_NULL_HANDLE, s_extension); @@ -1529,6 +1534,14 @@ VK_IMPORT_INSTANCE customBorderColorFeatures.pNext = NULL; } + if (s_extension[Extension::KHR_fragment_shader_barycentric].m_supported) + { + next->pNext = (VkBaseOutStructure*)&fragmentShaderBarycentricFeatures; + next = (VkBaseOutStructure*)&fragmentShaderBarycentricFeatures; + fragmentShaderBarycentricFeatures.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FRAGMENT_SHADER_BARYCENTRIC_FEATURES_KHR; + fragmentShaderBarycentricFeatures.pNext = NULL; + } + nextFeatures = deviceFeatures2.pNext; vkGetPhysicalDeviceFeatures2KHR(m_physicalDevice, &deviceFeatures2); @@ -1605,6 +1618,7 @@ VK_IMPORT_INSTANCE | (s_extension[Extension::EXT_conservative_rasterization ].m_supported ? BGFX_CAPS_CONSERVATIVE_RASTER : 0) | (s_extension[Extension::EXT_shader_viewport_index_layer].m_supported ? BGFX_CAPS_VIEWPORT_LAYER_ARRAY : 0) | (s_extension[Extension::KHR_draw_indirect_count ].m_supported && indirectDrawSupport ? BGFX_CAPS_DRAW_INDIRECT_COUNT : 0) + | (s_extension[Extension::KHR_fragment_shader_barycentric].m_supported ? BGFX_CAPS_FRAGMENT_BARYCENTRIC : 0) ; const uint32_t maxAttachments = bx::min(m_deviceProperties.limits.maxFragmentOutputAttachments, m_deviceProperties.limits.maxColorAttachments); diff --git a/tools/shaderc/shaderc.cpp b/tools/shaderc/shaderc.cpp index fef250c39f..9df53ac91f 100644 --- a/tools/shaderc/shaderc.cpp +++ b/tools/shaderc/shaderc.cpp @@ -144,6 +144,13 @@ namespace bgfx // "shadow1DProjLod", }; + static const char* s_EXT_fragment_shader_barycentric[] = + { + "gl_BaryCoord", + "gl_BaryCoordNoPersp", + NULL + }; + static const char* s_EXT_shader_texture_lod[] = { "texture2DLod", @@ -1718,6 +1725,8 @@ namespace bgfx } else { + bool hasBaryCoord = !bx::findIdentifierMatch(input, s_EXT_fragment_shader_barycentric).isEmpty(); + if (profile->lang == ShadingLang::GLSL || profile->lang == ShadingLang::ESSL) { @@ -1730,6 +1739,10 @@ namespace bgfx "#define shadow2DProj(_sampler, _coord) bgfxShadow2DProj(_sampler, _coord).x\n" ); } + else + { + hasBaryCoord = false; + } // gl_FragColor and gl_FragData are deprecated for essl > 300 if (profile->lang == ShadingLang::ESSL @@ -1757,6 +1770,14 @@ namespace bgfx } } + if (!hasBaryCoord) + { + preprocessor.writef( + "#define gl_BaryCoord vec3_splat(0.0)\n" + "#define gl_BaryCoordNoPersp vec3_splat(0.0)\n" + ); + } + for (InOut::const_iterator it = shaderInputs.begin(), itEnd = shaderInputs.end(); it != itEnd; ++it) { VaryingMap::const_iterator varyingIt = varyingMap.find(*it); @@ -1808,6 +1829,8 @@ namespace bgfx if (profile->lang == ShadingLang::PSSL) { preprocessor.writef(getPsslPreamble() ); + + hasBaryCoord = false; } preprocessor.writef( @@ -1889,6 +1912,22 @@ namespace bgfx } } + if (profile->lang == ShadingLang::HLSL) + { + if (profile->id < 610) + { + hasBaryCoord = false; + } + } + + if (!hasBaryCoord) + { + preprocessor.writef( + "#define gl_BaryCoord vec3_splat(0.0)\n" + "#define gl_BaryCoordNoPersp vec3_splat(0.0)\n" + ); + } + preprocessor.writef("#define void_main()"); preprocessor.writef(" \\\n\tvoid main("); @@ -1975,6 +2014,18 @@ namespace bgfx } } + if (hasBaryCoord) + { + preprocessor.writef( + " \\\n\t%sfloat3 gl_BaryCoord : SV_Barycentrics" + , arg++ > 0 ? ", " : " " + ); + preprocessor.writef( + " \\\n\t%snoperspective float3 gl_BaryCoordNoPersp : SV_Barycentrics1" + , arg++ > 0 ? ", " : " " + ); + } + preprocessor.writef( " \\\n\t)\n" ); @@ -2215,6 +2266,14 @@ namespace bgfx } } + if ('f' == _options.shaderType) + { + if (hasBaryCoord && profile->lang == ShadingLang::GLSL) + { + glsl_profile = 450; + } + } + if (glsl_profile < 400) { const bool usesTextureLod = false diff --git a/tools/shaderc/shaderc_metal.cpp b/tools/shaderc/shaderc_metal.cpp index 3c243ff9ea..5d6a8d5317 100644 --- a/tools/shaderc/shaderc_metal.cpp +++ b/tools/shaderc/shaderc_metal.cpp @@ -570,6 +570,12 @@ namespace bgfx { namespace metal { spirv_cross::CompilerMSL msl(std::move(spirv) ); + spirv_cross::CompilerMSL::Options mslOptions{}; + + mslOptions.msl_version = spirv_cross::CompilerMSL::Options::make_msl_version(2, 2); + + msl.set_msl_options(mslOptions); + auto executionModel = msl.get_execution_model(); spirv_cross::MSLResourceBinding newBinding; newBinding.stage = executionModel;