From f05953188599625b5ad8295e5a1424b07ec3ab93 Mon Sep 17 00:00:00 2001 From: Jamil Halabi Date: Fri, 4 Aug 2023 17:42:33 +0300 Subject: [PATCH] Added a new capability to check for PrimitiveID support (#3154) --- bindings/bf/bgfx.bf | 9 +++++++-- bindings/cs/bgfx.cs | 9 +++++++-- bindings/d/package.d | 7 ++++--- bindings/zig/bgfx.zig | 7 +++++-- include/bgfx/defines.h | 7 ++++--- scripts/bgfx.idl | 3 ++- src/renderer_d3d11.cpp | 3 +++ src/renderer_d3d12.cpp | 1 + src/renderer_gl.cpp | 7 +++++++ src/renderer_mtl.mm | 5 +++++ src/renderer_vk.cpp | 2 ++ tools/shaderc/shaderc.cpp | 7 ++++++- 12 files changed, 53 insertions(+), 14 deletions(-) diff --git a/bindings/bf/bgfx.bf b/bindings/bf/bgfx.bf index e010c49695..906a2377ca 100644 --- a/bindings/bf/bgfx.bf +++ b/bindings/bf/bgfx.bf @@ -1147,15 +1147,20 @@ public static class bgfx /// VertexId = 0x0000000008000000, + /// + /// PrimitiveID is available in fragment shader. + /// + PrimitiveId = 0x0000000010000000, + /// /// Viewport layer is available in vertex shader. /// - ViewportLayerArray = 0x0000000010000000, + ViewportLayerArray = 0x0000000020000000, /// /// Draw indirect with indirect count is supported. /// - DrawIndirectCount = 0x0000000020000000, + DrawIndirectCount = 0x0000000040000000, /// /// All texture compare modes are supported. diff --git a/bindings/cs/bgfx.cs b/bindings/cs/bgfx.cs index 7f0a1ba890..b8676ea610 100644 --- a/bindings/cs/bgfx.cs +++ b/bindings/cs/bgfx.cs @@ -1146,15 +1146,20 @@ public enum CapsFlags : ulong /// VertexId = 0x0000000008000000, + /// + /// PrimitiveID is available in fragment shader. + /// + PrimitiveId = 0x0000000010000000, + /// /// Viewport layer is available in vertex shader. /// - ViewportLayerArray = 0x0000000010000000, + ViewportLayerArray = 0x0000000020000000, /// /// Draw indirect with indirect count is supported. /// - DrawIndirectCount = 0x0000000020000000, + DrawIndirectCount = 0x0000000040000000, /// /// All texture compare modes are supported. diff --git a/bindings/d/package.d b/bindings/d/package.d index c55ef113f1..d05b8c89dc 100644 --- a/bindings/d/package.d +++ b/bindings/d/package.d @@ -10,7 +10,7 @@ import bindbc.bgfx.config; import bindbc.common.types: va_list; static import bgfx.fakeenum; -enum uint apiVersion = 121; +enum uint apiVersion = 122; alias ViewID = ushort; deprecated("Please use `ViewID` instead.") alias ViewId = ushort; @@ -521,8 +521,9 @@ enum CapFlags: CapFlags_{ 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. - viewportLayerArray = 0x0000_0000_1000_0000, ///Viewport layer is available in vertex shader. - drawIndirectCount = 0x0000_0000_2000_0000, ///Draw indirect with indirect count 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. } diff --git a/bindings/zig/bgfx.zig b/bindings/zig/bgfx.zig index 04a1f9d541..757888b0f4 100644 --- a/bindings/zig/bgfx.zig +++ b/bindings/zig/bgfx.zig @@ -708,11 +708,14 @@ pub const CapsFlags_VertexAttribUint10: CapsFlags = 0x0000000004000000; /// Rendering with VertexID only is supported. pub const CapsFlags_VertexId: CapsFlags = 0x0000000008000000; +/// PrimitiveID is available in fragment shader. +pub const CapsFlags_PrimitiveId: CapsFlags = 0x0000000010000000; + /// Viewport layer is available in vertex shader. -pub const CapsFlags_ViewportLayerArray: CapsFlags = 0x0000000010000000; +pub const CapsFlags_ViewportLayerArray: CapsFlags = 0x0000000020000000; /// Draw indirect with indirect count is supported. -pub const CapsFlags_DrawIndirectCount: CapsFlags = 0x0000000020000000; +pub const CapsFlags_DrawIndirectCount: CapsFlags = 0x0000000040000000; /// All texture compare modes are supported. pub const CapsFlags_TextureCompareAll: CapsFlags = 0x0000000000300000; diff --git a/include/bgfx/defines.h b/include/bgfx/defines.h index 9dd91f8429..0b7d1d6b38 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(121) +#define BGFX_API_VERSION UINT32_C(122) /** * Color RGB/alpha/depth write. When it's not specified write will be disabled. @@ -490,8 +490,9 @@ #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_VIEWPORT_LAYER_ARRAY UINT64_C(0x0000000010000000) //!< Viewport layer is available in vertex shader. -#define BGFX_CAPS_DRAW_INDIRECT_COUNT UINT64_C(0x0000000020000000) //!< Draw indirect with indirect count 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. /// 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 e437270c3a..2852fbef77 100644 --- a/scripts/bgfx.idl +++ b/scripts/bgfx.idl @@ -1,7 +1,7 @@ -- vim: syntax=lua -- bgfx interface -version(121) +version(122) typedef "bool" typedef "char" @@ -393,6 +393,7 @@ flag.Caps { bits = 64, base = 1, name = "Caps" } .VertexAttribHalf --- Vertex attribute half-float is supported. .VertexAttribUint10 --- Vertex attribute 10_10_10_2 is supported. .VertexId --- Rendering with VertexID only is supported. + .PrimitiveId --- PrimitiveID is available in fragment shader. .ViewportLayerArray --- Viewport layer is available in vertex shader. .DrawIndirectCount --- Draw indirect with indirect count is supported. .TextureCompareAll --- All texture compare modes are supported. diff --git a/src/renderer_d3d11.cpp b/src/renderer_d3d11.cpp index 460ea7d0a8..a2ddbd687a 100644 --- a/src/renderer_d3d11.cpp +++ b/src/renderer_d3d11.cpp @@ -1235,6 +1235,9 @@ namespace bgfx { namespace d3d11 | ((m_featureLevel >= D3D_FEATURE_LEVEL_11_1) ? BGFX_CAPS_IMAGE_RW : 0) + | ((m_featureLevel >= D3D_FEATURE_LEVEL_11_0) + ? BGFX_CAPS_PRIMITIVE_ID + : 0) ); m_timerQuerySupport = m_featureLevel >= D3D_FEATURE_LEVEL_10_0; diff --git a/src/renderer_d3d12.cpp b/src/renderer_d3d12.cpp index 3123716a90..e54c2e1fcd 100644 --- a/src/renderer_d3d12.cpp +++ b/src/renderer_d3d12.cpp @@ -1357,6 +1357,7 @@ namespace bgfx { namespace d3d12 | BGFX_CAPS_IMAGE_RW | BGFX_CAPS_VIEWPORT_LAYER_ARRAY | BGFX_CAPS_DRAW_INDIRECT_COUNT + | BGFX_CAPS_PRIMITIVE_ID ); g_caps.limits.maxTextureSize = D3D12_REQ_TEXTURE2D_U_OR_V_DIMENSION; g_caps.limits.maxTextureLayers = D3D12_REQ_TEXTURE2D_ARRAY_AXIS_DIMENSION; diff --git a/src/renderer_gl.cpp b/src/renderer_gl.cpp index 5b0e7e5b92..883dc48cb5 100644 --- a/src/renderer_gl.cpp +++ b/src/renderer_gl.cpp @@ -2896,6 +2896,13 @@ namespace bgfx { namespace gl : 0 ; + g_caps.supported |= false + || BX_ENABLED(BGFX_CONFIG_RENDERER_OPENGL >= 32) + || (m_gles3 && !BX_ENABLED(BX_PLATFORM_EMSCRIPTEN) && BX_ENABLED(BGFX_CONFIG_RENDERER_OPENGLES >= 32) ) + ? BGFX_CAPS_PRIMITIVE_ID + : 0 + ; + g_caps.supported |= false || s_extension[Extension::ARB_texture_cube_map_array].m_supported || s_extension[Extension::EXT_texture_cube_map_array].m_supported diff --git a/src/renderer_mtl.mm b/src/renderer_mtl.mm index 55b9ea013a..f79a2493c2 100644 --- a/src/renderer_mtl.mm +++ b/src/renderer_mtl.mm @@ -632,6 +632,11 @@ bool init(const Init& _init) | BGFX_CAPS_VERTEX_ID ); + g_caps.supported |= m_device.supportsFamily(MTLGPUFamilyApple7) + ? BGFX_CAPS_PRIMITIVE_ID + : 0 + ; + // Reference(s): // - Metal feature set tables // https://web.archive.org/web/20230330111145/https://developer.apple.com/metal/Metal-Feature-Set-Tables.pdf diff --git a/src/renderer_vk.cpp b/src/renderer_vk.cpp index 435d332fd2..d5832203c1 100644 --- a/src/renderer_vk.cpp +++ b/src/renderer_vk.cpp @@ -1570,6 +1570,7 @@ VK_IMPORT_INSTANCE m_deviceFeatures.shaderClipDistance = supportedFeatures.shaderClipDistance; m_deviceFeatures.shaderCullDistance = supportedFeatures.shaderCullDistance; m_deviceFeatures.shaderResourceMinLod = supportedFeatures.shaderResourceMinLod; + m_deviceFeatures.geometryShader = supportedFeatures.geometryShader; m_lineAASupport = true && s_extension[Extension::EXT_line_rasterization].m_supported @@ -1608,6 +1609,7 @@ VK_IMPORT_INSTANCE | BGFX_CAPS_VERTEX_ATTRIB_HALF | BGFX_CAPS_VERTEX_ATTRIB_UINT10 | BGFX_CAPS_VERTEX_ID + | (m_deviceFeatures.geometryShader ? BGFX_CAPS_PRIMITIVE_ID : 0) ); g_caps.supported |= 0 diff --git a/tools/shaderc/shaderc.cpp b/tools/shaderc/shaderc.cpp index 39e95a03f9..eb7cd559b0 100644 --- a/tools/shaderc/shaderc.cpp +++ b/tools/shaderc/shaderc.cpp @@ -1853,7 +1853,12 @@ namespace bgfx const bool hasFragCoord = !bx::strFind(input, "gl_FragCoord").isEmpty() || profile->id >= 400; const bool hasFragDepth = !bx::strFind(input, "gl_FragDepth").isEmpty(); const bool hasFrontFacing = !bx::strFind(input, "gl_FrontFacing").isEmpty(); - const bool hasPrimitiveId = !bx::strFind(input, "gl_PrimitiveID").isEmpty(); + const bool hasPrimitiveId = !bx::strFind(input, "gl_PrimitiveID").isEmpty() && BGFX_CAPS_PRIMITIVE_ID; + + if (!hasPrimitiveId) + { + preprocessor.writef("#define gl_PrimitiveID 0\n"); + } bool hasFragData[8] = {}; uint32_t numFragData = 0;