Skip to content

Commit

Permalink
Added a new capability to check for PrimitiveID support (#3154)
Browse files Browse the repository at this point in the history
  • Loading branch information
jay3d authored Aug 4, 2023
1 parent 3101a0d commit f059531
Show file tree
Hide file tree
Showing 12 changed files with 53 additions and 14 deletions.
9 changes: 7 additions & 2 deletions bindings/bf/bgfx.bf
Original file line number Diff line number Diff line change
Expand Up @@ -1147,15 +1147,20 @@ public static class bgfx
/// </summary>
VertexId = 0x0000000008000000,

/// <summary>
/// PrimitiveID is available in fragment shader.
/// </summary>
PrimitiveId = 0x0000000010000000,

/// <summary>
/// Viewport layer is available in vertex shader.
/// </summary>
ViewportLayerArray = 0x0000000010000000,
ViewportLayerArray = 0x0000000020000000,

/// <summary>
/// Draw indirect with indirect count is supported.
/// </summary>
DrawIndirectCount = 0x0000000020000000,
DrawIndirectCount = 0x0000000040000000,

/// <summary>
/// All texture compare modes are supported.
Expand Down
9 changes: 7 additions & 2 deletions bindings/cs/bgfx.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1146,15 +1146,20 @@ public enum CapsFlags : ulong
/// </summary>
VertexId = 0x0000000008000000,

/// <summary>
/// PrimitiveID is available in fragment shader.
/// </summary>
PrimitiveId = 0x0000000010000000,

/// <summary>
/// Viewport layer is available in vertex shader.
/// </summary>
ViewportLayerArray = 0x0000000010000000,
ViewportLayerArray = 0x0000000020000000,

/// <summary>
/// Draw indirect with indirect count is supported.
/// </summary>
DrawIndirectCount = 0x0000000020000000,
DrawIndirectCount = 0x0000000040000000,

/// <summary>
/// All texture compare modes are supported.
Expand Down
7 changes: 4 additions & 3 deletions bindings/d/package.d
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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.
}

Expand Down
7 changes: 5 additions & 2 deletions bindings/zig/bgfx.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
7 changes: 4 additions & 3 deletions include/bgfx/defines.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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 \
Expand Down
3 changes: 2 additions & 1 deletion scripts/bgfx.idl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
-- vim: syntax=lua
-- bgfx interface

version(121)
version(122)

typedef "bool"
typedef "char"
Expand Down Expand Up @@ -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.
Expand Down
3 changes: 3 additions & 0 deletions src/renderer_d3d11.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions src/renderer_d3d12.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
7 changes: 7 additions & 0 deletions src/renderer_gl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions src/renderer_mtl.mm
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions src/renderer_vk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
7 changes: 6 additions & 1 deletion tools/shaderc/shaderc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit f059531

Please sign in to comment.