Browse Source

Added ability to configure minimum uniform buffer size. PR #3478.

Branimir Karadžić 1 month ago
parent
commit
55f997002f
2 changed files with 17 additions and 4 deletions
  1. 7 4
      src/bgfx_p.h
  2. 10 0
      src/config.h

+ 7 - 4
src/bgfx_p.h

@@ -1478,7 +1478,7 @@ namespace bgfx
 	class UniformBuffer
 	class UniformBuffer
 	{
 	{
 	public:
 	public:
-		static UniformBuffer* create(uint32_t _size) // = BGFX_CONFIG_UNIFORM_BUFFER_SIZE)
+		static UniformBuffer* create(uint32_t _size)
 		{
 		{
 			const uint32_t structSize = sizeof(UniformBuffer)-sizeof(UniformBuffer::m_buffer);
 			const uint32_t structSize = sizeof(UniformBuffer)-sizeof(UniformBuffer::m_buffer);
 
 
@@ -1493,13 +1493,16 @@ namespace bgfx
 			bx::free(g_allocator, _uniformBuffer);
 			bx::free(g_allocator, _uniformBuffer);
 		}
 		}
 
 
-		static void update(UniformBuffer** _uniformBuffer, uint32_t _threshold = 64<<10, uint32_t _grow = 1<<20)
+		static void update(UniformBuffer** _uniformBuffer)
 		{
 		{
+			constexpr uint32_t kThreshold = BGFX_CONFIG_UNIFORM_BUFFER_RESIZE_THRESHOLD_SIZE;
+			constexpr uint32_t kIncrement = BGFX_CONFIG_UNIFORM_BUFFER_RESIZE_INCREMENT_SIZE;
+
 			UniformBuffer* uniformBuffer = *_uniformBuffer;
 			UniformBuffer* uniformBuffer = *_uniformBuffer;
-			if (_threshold >= uniformBuffer->m_size - uniformBuffer->m_pos)
+			if (kThreshold >= uniformBuffer->m_size - uniformBuffer->m_pos)
 			{
 			{
 				const uint32_t structSize = sizeof(UniformBuffer)-sizeof(UniformBuffer::m_buffer);
 				const uint32_t structSize = sizeof(UniformBuffer)-sizeof(UniformBuffer::m_buffer);
-				uint32_t size = bx::alignUp(uniformBuffer->m_size + _grow, 16);
+				uint32_t size = bx::alignUp(uniformBuffer->m_size + kIncrement, 16);
 				void*    data = bx::realloc(g_allocator, uniformBuffer, size+structSize);
 				void*    data = bx::realloc(g_allocator, uniformBuffer, size+structSize);
 				uniformBuffer = reinterpret_cast<UniformBuffer*>(data);
 				uniformBuffer = reinterpret_cast<UniformBuffer*>(data);
 				uniformBuffer->m_size = size;
 				uniformBuffer->m_size = size;

+ 10 - 0
src/config.h

@@ -338,6 +338,16 @@ static_assert(bx::isPowerOf2(BGFX_CONFIG_MAX_VIEWS), "BGFX_CONFIG_MAX_VIEWS must
 #	define BGFX_CONFIG_MIN_UNIFORM_BUFFER_SIZE (1<<20)
 #	define BGFX_CONFIG_MIN_UNIFORM_BUFFER_SIZE (1<<20)
 #endif // BGFX_CONFIG_MIN_UNIFORM_BUFFER_SIZE
 #endif // BGFX_CONFIG_MIN_UNIFORM_BUFFER_SIZE
 
 
+#ifndef BGFX_CONFIG_UNIFORM_BUFFER_RESIZE_THRESHOLD_SIZE
+/// Max amount of unused uniform buffer space before uniform buffer resize.
+#	define BGFX_CONFIG_UNIFORM_BUFFER_RESIZE_THRESHOLD_SIZE (64<<10)
+#endif // BGFX_CONFIG_UNIFORM_BUFFER_RESIZE_THRESHOLD_SIZE
+
+#ifndef BGFX_CONFIG_UNIFORM_BUFFER_RESIZE_INCREMENT_SIZE
+/// Increment of uniform buffer resize.
+#	define BGFX_CONFIG_UNIFORM_BUFFER_RESIZE_INCREMENT_SIZE (1<<20)
+#endif // BGFX_CONFIG_UNIFORM_BUFFER_RESIZE_INCREMENT_SIZE
+
 #ifndef BGFX_CONFIG_CACHED_DEVICE_MEMORY_ALLOCATIONS_SIZE
 #ifndef BGFX_CONFIG_CACHED_DEVICE_MEMORY_ALLOCATIONS_SIZE
 /// Amount of allowed memory allocations left on device to use for recycling during
 /// 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
 /// later allocations. This can be beneficial in case the driver is slow allocating memory