diff --git a/bindings/bf/bgfx.bf b/bindings/bf/bgfx.bf index b90b69084..a1e0918d8 100644 --- a/bindings/bf/bgfx.bf +++ b/bindings/bf/bgfx.bf @@ -2083,8 +2083,9 @@ public static class bgfx public uint32 maxOcclusionQueries; public uint32 maxEncoders; public uint32 minResourceCbSize; - public uint32 transientVbSize; - public uint32 transientIbSize; + public uint32 maxTransientVbSize; + public uint32 matTansientIbSize; + public uint32 minUniformBufferSize; } public RendererType rendererType; @@ -2138,8 +2139,9 @@ public static class bgfx { public uint16 maxEncoders; public uint32 minResourceCbSize; - public uint32 transientVbSize; - public uint32 transientIbSize; + public uint32 maxTransientVbSize; + public uint32 matTransientIbSize; + public uint32 minUniformBufferSize; } public RendererType type; diff --git a/bindings/c3/bgfx.c3 b/bindings/c3/bgfx.c3 index abf7a7c25..f0001a616 100644 --- a/bindings/c3/bgfx.c3 +++ b/bindings/c3/bgfx.c3 @@ -1379,9 +1379,11 @@ struct CapsLimits // Minimum resource command buffer size. uint minResourceCbSize; // Maximum transient vertex buffer size. - uint transientVbSize; + uint maxTransientVbSize; // Maximum transient index buffer size. - uint transientIbSize; + uint matTansientIbSize; + // Mimimum uniform buffer size. + uint minUniformBufferSize; } // Renderer capabilities. @@ -1491,9 +1493,11 @@ struct InitLimits // Minimum resource command buffer size. uint minResourceCbSize; // Maximum transient vertex buffer size. - uint transientVbSize; + uint maxTransientVbSize; // Maximum transient index buffer size. - uint transientIbSize; + uint matTransientIbSize; + // Mimimum uniform buffer size. + uint minUniformBufferSize; } // Initialization parameters used by `bgfx::init`. diff --git a/bindings/cs/bgfx.cs b/bindings/cs/bgfx.cs index 034cb09a5..b60deb9ea 100644 --- a/bindings/cs/bgfx.cs +++ b/bindings/cs/bgfx.cs @@ -2064,8 +2064,9 @@ public static partial class bgfx public uint maxOcclusionQueries; public uint maxEncoders; public uint minResourceCbSize; - public uint transientVbSize; - public uint transientIbSize; + public uint maxTransientVbSize; + public uint matTansientIbSize; + public uint minUniformBufferSize; } public RendererType rendererType; @@ -2114,8 +2115,9 @@ public static partial class bgfx { public ushort maxEncoders; public uint minResourceCbSize; - public uint transientVbSize; - public uint transientIbSize; + public uint maxTransientVbSize; + public uint matTransientIbSize; + public uint minUniformBufferSize; } public RendererType type; diff --git a/bindings/d/package.d b/bindings/d/package.d index 80c11c179..5212c4570 100644 --- a/bindings/d/package.d +++ b/bindings/d/package.d @@ -9,7 +9,7 @@ import bindbc.common.types: c_int64, c_uint64, va_list; import bindbc.bgfx.config; static import bgfx.impl; -enum uint apiVersion = 131; +enum uint apiVersion = 132; alias ViewID = ushort; @@ -1027,8 +1027,9 @@ extern(C++, "bgfx") struct Caps{ uint maxOcclusionQueries; ///Maximum number of occlusion query handles. uint maxEncoders; ///Maximum number of encoder threads. uint minResourceCBSize; ///Minimum resource command buffer size. - uint transientVBSize; ///Maximum transient vertex buffer size. - uint transientIBSize; ///Maximum transient index buffer size. + uint maxTransientVBSize; ///Maximum transient vertex buffer size. + uint matTansientIBSize; ///Maximum transient index buffer size. + uint minUniformBufferSize; ///Mimimum uniform buffer size. } RendererType rendererType; ///Renderer backend type. See: `bgfx::RendererType` @@ -1134,8 +1135,9 @@ extern(C++, "bgfx") struct Init{ extern(C++) struct Limits{ ushort maxEncoders; ///Maximum number of encoder threads. uint minResourceCBSize; ///Minimum resource command buffer size. - uint transientVBSize; ///Maximum transient vertex buffer size. - uint transientIBSize; ///Maximum transient index buffer size. + uint maxTransientVBSize; ///Maximum transient vertex buffer size. + uint matTransientIBSize; ///Maximum transient index buffer size. + uint minUniformBufferSize; ///Mimimum uniform buffer size. extern(D) mixin(joinFnBinds((){ FnBind[] ret = [ {q{void}, q{this}, q{}, ext: `C++`}, diff --git a/bindings/zig/bgfx.zig b/bindings/zig/bgfx.zig index e8b28d978..1a87a921a 100644 --- a/bindings/zig/bgfx.zig +++ b/bindings/zig/bgfx.zig @@ -1309,8 +1309,9 @@ pub const Caps = extern struct { maxOcclusionQueries: u32, maxEncoders: u32, minResourceCbSize: u32, - transientVbSize: u32, - transientIbSize: u32, + maxTransientVbSize: u32, + matTansientIbSize: u32, + minUniformBufferSize: u32, }; rendererType: RendererType, @@ -1354,8 +1355,9 @@ pub const Init = extern struct { pub const Limits = extern struct { maxEncoders: u16, minResourceCbSize: u32, - transientVbSize: u32, - transientIbSize: u32, + maxTransientVbSize: u32, + matTransientIbSize: u32, + minUniformBufferSize: u32, }; type: RendererType, diff --git a/include/bgfx/bgfx.h b/include/bgfx/bgfx.h index b41f4cce1..0bc135070 100644 --- a/include/bgfx/bgfx.h +++ b/include/bgfx/bgfx.h @@ -715,10 +715,11 @@ namespace bgfx { Limits(); - uint16_t maxEncoders; //!< Maximum number of encoder threads. - uint32_t minResourceCbSize; //!< Minimum resource command buffer size. - uint32_t transientVbSize; //!< Maximum transient vertex buffer size. - uint32_t transientIbSize; //!< Maximum transient index buffer size. + uint16_t maxEncoders; //!< Maximum number of encoder threads. + uint32_t minResourceCbSize; //!< Minimum resource command buffer size. + uint32_t maxTransientVbSize; //!< Maximum transient vertex buffer size. + uint32_t maxTransientIbSize; //!< Maximum transient index buffer size. + uint32_t minUniformBufferSize; //!< Mimimum uniform buffer size. }; Limits limits; //!< Configurable runtime limits. @@ -817,8 +818,9 @@ namespace bgfx uint32_t maxOcclusionQueries; //!< Maximum number of occlusion query handles. uint32_t maxEncoders; //!< Maximum number of encoder threads. uint32_t minResourceCbSize; //!< Minimum resource command buffer size. - uint32_t transientVbSize; //!< Maximum transient vertex buffer size. - uint32_t transientIbSize; //!< Maximum transient index buffer size. + uint32_t maxTransientVbSize; //!< Maximum transient vertex buffer size. + uint32_t maxTransientIbSize; //!< Maximum transient index buffer size. + uint32_t minUniformBufferSize; //!< Mimimum uniform buffer size. }; Limits limits; //!< Renderer runtime limits. diff --git a/include/bgfx/c99/bgfx.h b/include/bgfx/c99/bgfx.h index b21a7eb5e..edf0a01b3 100644 --- a/include/bgfx/c99/bgfx.h +++ b/include/bgfx/c99/bgfx.h @@ -538,8 +538,9 @@ typedef struct bgfx_caps_limits_s uint32_t maxOcclusionQueries; /** Maximum number of occlusion query handles. */ uint32_t maxEncoders; /** Maximum number of encoder threads. */ uint32_t minResourceCbSize; /** Minimum resource command buffer size. */ - uint32_t transientVbSize; /** Maximum transient vertex buffer size. */ - uint32_t transientIbSize; /** Maximum transient index buffer size. */ + uint32_t maxTransientVbSize; /** Maximum transient vertex buffer size. */ + uint32_t matTansientIbSize; /** Maximum transient index buffer size. */ + uint32_t minUniformBufferSize; /** Mimimum uniform buffer size. */ } bgfx_caps_limits_t; @@ -664,8 +665,9 @@ typedef struct bgfx_init_limits_s { uint16_t maxEncoders; /** Maximum number of encoder threads. */ uint32_t minResourceCbSize; /** Minimum resource command buffer size. */ - uint32_t transientVbSize; /** Maximum transient vertex buffer size. */ - uint32_t transientIbSize; /** Maximum transient index buffer size. */ + uint32_t maxTransientVbSize; /** Maximum transient vertex buffer size. */ + uint32_t matTransientIbSize; /** Maximum transient index buffer size. */ + uint32_t minUniformBufferSize; /** Mimimum uniform buffer size. */ } bgfx_init_limits_t; diff --git a/include/bgfx/defines.h b/include/bgfx/defines.h index 69290b621..f7435ee82 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(131) +#define BGFX_API_VERSION UINT32_C(132) /** * Color RGB/alpha/depth write. When it's not specified write will be disabled. diff --git a/scripts/bgfx.idl b/scripts/bgfx.idl index bec5d3433..166916dc9 100644 --- a/scripts/bgfx.idl +++ b/scripts/bgfx.idl @@ -1,7 +1,7 @@ -- vim: syntax=lua -- bgfx interface -version(131) +version(132) typedef "bool" typedef "char" @@ -732,8 +732,9 @@ struct.Limits { namespace = "Caps" } .maxOcclusionQueries "uint32_t" --- Maximum number of occlusion query handles. .maxEncoders "uint32_t" --- Maximum number of encoder threads. .minResourceCbSize "uint32_t" --- Minimum resource command buffer size. - .transientVbSize "uint32_t" --- Maximum transient vertex buffer size. - .transientIbSize "uint32_t" --- Maximum transient index buffer size. + .maxTransientVbSize "uint32_t" --- Maximum transient vertex buffer size. + .matTansientIbSize "uint32_t" --- Maximum transient index buffer size. + .minUniformBufferSize "uint32_t" --- Mimimum uniform buffer size. --- Renderer capabilities. struct.Caps @@ -803,10 +804,11 @@ struct.Resolution { ctor } --- Configurable runtime limits parameters. struct.Limits { ctor, namespace = "Init" } - .maxEncoders "uint16_t" --- Maximum number of encoder threads. - .minResourceCbSize "uint32_t" --- Minimum resource command buffer size. - .transientVbSize "uint32_t" --- Maximum transient vertex buffer size. - .transientIbSize "uint32_t" --- Maximum transient index buffer size. + .maxEncoders "uint16_t" --- Maximum number of encoder threads. + .minResourceCbSize "uint32_t" --- Minimum resource command buffer size. + .maxTransientVbSize "uint32_t" --- Maximum transient vertex buffer size. + .matTransientIbSize "uint32_t" --- Maximum transient index buffer size. + .minUniformBufferSize "uint32_t" --- Mimimum uniform buffer size. --- Initialization parameters used by `bgfx::init`. struct.Init { ctor } diff --git a/src/bgfx.cpp b/src/bgfx.cpp index 98b1cd2a2..83856668d 100644 --- a/src/bgfx.cpp +++ b/src/bgfx.cpp @@ -1649,8 +1649,9 @@ namespace bgfx LIMITS(maxOcclusionQueries); LIMITS(maxEncoders); LIMITS(minResourceCbSize); - LIMITS(transientVbSize); - LIMITS(transientIbSize); + LIMITS(maxTransientVbSize); + LIMITS(maxTransientIbSize); + LIMITS(minUniformBufferSize); #undef LIMITS BX_TRACE(""); @@ -2016,14 +2017,14 @@ namespace bgfx m_textVideoMemBlitter.init(m_init.resolution.debugTextScale); m_clearQuad.init(); - m_submit->m_transientVb = createTransientVertexBuffer(_init.limits.transientVbSize); - m_submit->m_transientIb = createTransientIndexBuffer(_init.limits.transientIbSize); + m_submit->m_transientVb = createTransientVertexBuffer(_init.limits.maxTransientVbSize); + m_submit->m_transientIb = createTransientIndexBuffer(_init.limits.maxTransientIbSize); frame(); if (BX_ENABLED(BGFX_CONFIG_MULTITHREADED) ) { - m_submit->m_transientVb = createTransientVertexBuffer(_init.limits.transientVbSize); - m_submit->m_transientIb = createTransientIndexBuffer(_init.limits.transientIbSize); + m_submit->m_transientVb = createTransientVertexBuffer(_init.limits.maxTransientVbSize); + m_submit->m_transientIb = createTransientIndexBuffer(_init.limits.maxTransientIbSize); frame(); } @@ -3511,8 +3512,9 @@ namespace bgfx Init::Limits::Limits() : maxEncoders(BGFX_CONFIG_DEFAULT_MAX_ENCODERS) , minResourceCbSize(BGFX_CONFIG_MIN_RESOURCE_COMMAND_BUFFER_SIZE) - , transientVbSize(BGFX_CONFIG_TRANSIENT_VERTEX_BUFFER_SIZE) - , transientIbSize(BGFX_CONFIG_TRANSIENT_INDEX_BUFFER_SIZE) + , maxTransientVbSize(BGFX_CONFIG_MAX_TRANSIENT_VERTEX_BUFFER_SIZE) + , maxTransientIbSize(BGFX_CONFIG_MAX_TRANSIENT_INDEX_BUFFER_SIZE) + , minUniformBufferSize(BGFX_CONFIG_MIN_UNIFORM_BUFFER_SIZE) { } @@ -3606,8 +3608,9 @@ namespace bgfx g_caps.limits.maxFBAttachments = 1; g_caps.limits.maxEncoders = init.limits.maxEncoders; g_caps.limits.minResourceCbSize = init.limits.minResourceCbSize; - g_caps.limits.transientVbSize = init.limits.transientVbSize; - g_caps.limits.transientIbSize = init.limits.transientIbSize; + g_caps.limits.maxTransientVbSize = init.limits.maxTransientVbSize; + g_caps.limits.maxTransientIbSize = init.limits.maxTransientIbSize; + g_caps.limits.minUniformBufferSize = init.limits.minUniformBufferSize; g_caps.vendorId = init.vendorId; g_caps.deviceId = init.deviceId; diff --git a/src/bgfx_p.h b/src/bgfx_p.h index eda27d83f..ac1049438 100644 --- a/src/bgfx_p.h +++ b/src/bgfx_p.h @@ -1478,7 +1478,7 @@ namespace bgfx class UniformBuffer { public: - static UniformBuffer* create(uint32_t _size = 1<<20) + static UniformBuffer* create(uint32_t _size) // = BGFX_CONFIG_UNIFORM_BUFFER_SIZE) { const uint32_t structSize = sizeof(UniformBuffer)-sizeof(UniformBuffer::m_buffer); @@ -2191,7 +2191,7 @@ namespace bgfx for (uint32_t ii = 0; ii < num; ++ii) { - m_uniformBuffer[ii] = UniformBuffer::create(); + m_uniformBuffer[ii] = UniformBuffer::create(g_caps.limits.minUniformBufferSize); } } @@ -2247,7 +2247,7 @@ namespace bgfx { const uint32_t offset = bx::strideAlign(m_iboffset, _indexSize); uint32_t iboffset = offset + _num*_indexSize; - iboffset = bx::min(iboffset, g_caps.limits.transientIbSize); + iboffset = bx::min(iboffset, g_caps.limits.maxTransientIbSize); const uint32_t num = (iboffset-offset)/_indexSize; return num; } @@ -2266,7 +2266,7 @@ namespace bgfx { uint32_t offset = bx::strideAlign(m_vboffset, _stride); uint32_t vboffset = offset + _num * _stride; - vboffset = bx::min(vboffset, g_caps.limits.transientVbSize); + vboffset = bx::min(vboffset, g_caps.limits.maxTransientVbSize); uint32_t num = (vboffset-offset)/_stride; return num; } diff --git a/src/config.h b/src/config.h index 2107b235b..906a96fcf 100644 --- a/src/config.h +++ b/src/config.h @@ -321,37 +321,46 @@ static_assert(bx::isPowerOf2(BGFX_CONFIG_MAX_VIEWS), "BGFX_CONFIG_MAX_VIEWS must # define BGFX_CONFIG_MIN_RESOURCE_COMMAND_BUFFER_SIZE (64<<10) #endif // BGFX_CONFIG_MIN_RESOURCE_COMMAND_BUFFER_SIZE -#ifndef BGFX_CONFIG_TRANSIENT_VERTEX_BUFFER_SIZE -# define BGFX_CONFIG_TRANSIENT_VERTEX_BUFFER_SIZE (6<<20) -#endif // BGFX_CONFIG_TRANSIENT_VERTEX_BUFFER_SIZE +#ifndef BGFX_CONFIG_MAX_TRANSIENT_VERTEX_BUFFER_SIZE +/// Maximum transient vertex buffer size. There is no growth, and all transient +/// vertices must fit into this buffer. +# define BGFX_CONFIG_MAX_TRANSIENT_VERTEX_BUFFER_SIZE (6<<20) +#endif // BGFX_CONFIG_MAX_TRANSIENT_VERTEX_BUFFER_SIZE -#ifndef BGFX_CONFIG_TRANSIENT_INDEX_BUFFER_SIZE -# define BGFX_CONFIG_TRANSIENT_INDEX_BUFFER_SIZE (2<<20) -#endif // BGFX_CONFIG_TRANSIENT_INDEX_BUFFER_SIZE +#ifndef BGFX_CONFIG_MAX_TRANSIENT_INDEX_BUFFER_SIZE +/// Maximum transient index buffer size. There is no growth, and all transient +/// indices must fit into this buffer. +# define BGFX_CONFIG_MAX_TRANSIENT_INDEX_BUFFER_SIZE (2<<20) +#endif // BGFX_CONFIG_MAX_TRANSIENT_INDEX_BUFFER_SIZE -#ifndef BGFX_CONFIG_PER_FRAME_SCRATCH_STAGING_BUFFER_SIZE +#ifndef BGFX_CONFIG_MIN_UNIFORM_BUFFER_SIZE +/// Mimumum uniform buffer size. This buffer will resize on demand. +# define BGFX_CONFIG_MIN_UNIFORM_BUFFER_SIZE (1<<20) +#endif // BGFX_CONFIG_MIN_UNIFORM_BUFFER_SIZE + +#ifndef BGFX_CONFIG_CACHED_DEVICE_MEMORY_ALLOCATIONS_SIZE +/// Amount of allowed memory allocations left on device to use for recycling during +/// later allocations. This can be beneficial in case the driver is slow allocating memory +/// on the device. +/// Note: Currently only used by the Vulkan backend. +# define BGFX_CONFIG_CACHED_DEVICE_MEMORY_ALLOCATIONS_SIZE (128 << 20) +#endif // BGFX_CONFIG_CACHED_DEVICE_MEMORY_ALLOCATIONS_SIZE + +#ifndef BGFX_CONFIG_MAX_STAGING_SCRATCH_BUFFER_SIZE +/// The threshold of data size above which the staging scratch buffer will +/// not be used, but instead a separate device memory allocation will take +/// place to stage the data for copying to device. +# define BGFX_CONFIG_MAX_STAGING_SCRATCH_BUFFER_SIZE (16 << 20) +#endif // BGFX_CONFIG_MAX_STAGING_SCRATCH_BUFFER_SIZE + +#ifndef BGFX_CONFIG_MAX_SCRATCH_STAGING_BUFFER_PER_FRAME_SIZE /// Amount of scratch buffer size (per in-flight frame) that will be reserved /// for staging data for copying to the device (such as vertex buffer data, /// texture data, etc). This buffer will be used instead of allocating memory /// on device separately for every data copy. /// Note: Currently only used by the Vulkan backend. -# define BGFX_CONFIG_PER_FRAME_SCRATCH_STAGING_BUFFER_SIZE (32<<20) -#endif - -#ifndef BGFX_CONFIG_MAX_BYTES_CACHED_DEVICE_MEMORY_ALLOCATIONS -/// Amount of allowed memory allocations left on device to use for recycling during -/// later allocations. This can be beneficial in case the driver is slow allocating memory -/// on the device. -/// Note: Currently only used by the Vulkan backend. -# define BGFX_CONFIG_MAX_BYTES_CACHED_DEVICE_MEMORY_ALLOCATIONS (128 << 20) -#endif - -#ifndef BGFX_CONFIG_MAX_STAGING_SIZE_FOR_SCRATCH_BUFFER -/// The threshold of data size above which the staging scratch buffer will -/// not be used, but instead a separate device memory allocation will take -/// place to stage the data for copying to device. -# define BGFX_CONFIG_MAX_STAGING_SIZE_FOR_SCRATCH_BUFFER (16 << 20) -#endif +# define BGFX_CONFIG_MAX_SCRATCH_STAGING_BUFFER_PER_FRAME_SIZE (32<<20) +#endif // BGFX_CONFIG_MAX_SCRATCH_STAGING_BUFFER_PER_FRAME_SIZE #ifndef BGFX_CONFIG_MAX_INSTANCE_DATA_COUNT # define BGFX_CONFIG_MAX_INSTANCE_DATA_COUNT 5 diff --git a/src/renderer_vk.cpp b/src/renderer_vk.cpp index 7b513f3d7..6dce7ff78 100644 --- a/src/renderer_vk.cpp +++ b/src/renderer_vk.cpp @@ -2026,7 +2026,7 @@ VK_IMPORT_DEVICE for (uint32_t ii = 0; ii < m_numFramesInFlight; ++ii) { BX_TRACE("Create scratch staging buffer %d", ii); - m_scratchStagingBuffer[ii].createStaging(BGFX_CONFIG_PER_FRAME_SCRATCH_STAGING_BUFFER_SIZE); + m_scratchStagingBuffer[ii].createStaging(BGFX_CONFIG_MAX_SCRATCH_STAGING_BUFFER_PER_FRAME_SIZE); } } @@ -4524,7 +4524,7 @@ VK_IMPORT_DEVICE StagingBufferVK result; ScratchBufferVK &scratch = m_scratchStagingBuffer[m_cmd.m_currentFrameInFlight]; - if (_size <= BGFX_CONFIG_MAX_STAGING_SIZE_FOR_SCRATCH_BUFFER) + if (_size <= BGFX_CONFIG_MAX_STAGING_SCRATCH_BUFFER_SIZE) { const uint32_t scratchOffset = scratch.alloc(_size, _align); @@ -4750,7 +4750,7 @@ VK_DESTROY } totalSizeCached += _alloc.size; - while (totalSizeCached > BGFX_CONFIG_MAX_BYTES_CACHED_DEVICE_MEMORY_ALLOCATIONS) + while (totalSizeCached > BGFX_CONFIG_CACHED_DEVICE_MEMORY_ALLOCATIONS_SIZE) { BX_ASSERT(lru.getNumHandles() > 0, "Memory badly counted."); uint16_t handle = lru.getBack();