MCPcopy Create free account
hub / github.com/defold/defold / PrepareScatchBuffer

Function PrepareScatchBuffer

engine/graphics/src/vulkan/graphics_vulkan.cpp:3081–3103  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3079 }
3080
3081 static void PrepareScatchBuffer(VulkanContext* context, ScratchBuffer* scratchBuffer, VulkanProgram* program_ptr)
3082 {
3083 const uint32_t num_uniform_buffers = program_ptr->m_UniformBufferCount;
3084 const bool resize_scratch_buffer = program_ptr->m_UniformDataSizeAligned > (scratchBuffer->m_DeviceBuffer.m_MemorySize - scratchBuffer->m_MappedDataCursor);
3085
3086 if (resize_scratch_buffer)
3087 {
3088 // Double the buffer size, or grow to fit the current program's needs,
3089 // whichever is larger. This avoids repeated small resizes when many
3090 // materials with large uniform blocks are drawn in the same frame.
3091 const uint32_t current_size = scratchBuffer->m_DeviceBuffer.m_MemorySize;
3092 const uint32_t needed_size = scratchBuffer->m_MappedDataCursor + program_ptr->m_UniformDataSizeAligned;
3093 const uint32_t new_size = dmMath::Max(current_size * 2, needed_size);
3094 VkResult res = ResizeScratchBuffer(context, new_size, scratchBuffer);
3095 CHECK_VK_ERROR(res);
3096 }
3097
3098 // The dynamic offset buffer is pre-allocated at context init to
3099 // MAX_SET_COUNT * MAX_BINDINGS_PER_SET_COUNT, which is the upper bound
3100 // for any program. Assert rather than silently reallocating.
3101 assert(context->m_DynamicOffsetBuffer != 0x0);
3102 assert(context->m_DynamicOffsetBufferSize >= num_uniform_buffers);
3103 }
3104
3105 static void DrawSetupCompute(VulkanContext* context, VkCommandBuffer vk_command_buffer, ScratchBuffer* scratchBuffer)
3106 {

Callers 2

DrawSetupComputeFunction · 0.85
DrawSetupFunction · 0.85

Calls 3

ResizeScratchBufferFunction · 0.85
MaxFunction · 0.50
assertFunction · 0.50

Tested by

no test coverage detected