MCPcopy Create free account
hub / github.com/comaps/comaps / ApplyBytes

Method ApplyBytes

libs/shaders/vulkan_program_params.cpp:112–157  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

110}
111
112void VulkanProgramParamsSetter::ApplyBytes(ref_ptr<dp::vulkan::VulkanBaseContext> context, void const * data,
113 uint32_t sizeInBytes)
114{
115 CHECK_THREAD_CHECKER(m_threadChecker, ());
116 auto const & mm = m_objectManager->GetMemoryManager();
117 auto const alignedSize = mm.GetAligned(sizeInBytes, m_sizeAlignment);
118
119 auto & ub = m_uniformBuffers[m_currentInflightFrameIndex];
120
121 int index = -1;
122 for (int i = 0; i < static_cast<int>(ub.size()); ++i)
123 {
124 if (ub[i].m_freeOffset + alignedSize <= kUniformBufferSizeInBytes)
125 {
126 index = i;
127 break;
128 }
129 }
130 if (index < 0)
131 {
132 uint32_t sizeAlignment, offsetAlignment;
133 ub.emplace_back(CreateUniformBuffer(context->GetDevice(), m_objectManager, sizeAlignment, offsetAlignment));
134 CHECK_EQUAL(m_sizeAlignment, sizeAlignment, ());
135 CHECK_EQUAL(m_offsetAlignment, offsetAlignment, ());
136 index = static_cast<int>(ub.size()) - 1;
137 }
138 CHECK_LESS_OR_EQUAL(ub[index].m_freeOffset + alignedSize, kUniformBufferSizeInBytes, ());
139
140 auto const alignedOffset = ub[index].m_freeOffset;
141 uint8_t * ptr = ub[index].m_pointer + alignedOffset;
142
143 // Update offset and align it.
144 ub[index].m_freeOffset += alignedSize;
145 ub[index].m_freeOffset =
146 std::min(mm.GetAligned(ub[index].m_freeOffset, m_offsetAlignment), ub[index].m_object.GetAlignedSize());
147
148 memcpy(ptr, data, sizeInBytes);
149
150 dp::vulkan::ParamDescriptor descriptor;
151 descriptor.m_type = dp::vulkan::ParamDescriptor::Type::DynamicUniformBuffer;
152 descriptor.m_bufferDescriptor.buffer = ub[index].m_object.m_buffer;
153 descriptor.m_bufferDescriptor.range = alignedSize;
154 descriptor.m_bufferDynamicOffset = alignedOffset;
155 descriptor.m_id = static_cast<uint32_t>(index);
156 context->ApplyParamDescriptor(std::move(descriptor));
157}
158
159void VulkanProgramParamsSetter::Apply(ref_ptr<dp::GraphicsContext> context, ref_ptr<dp::GpuProgram> program,
160 MapProgramParams const & params)

Callers

nothing calls this directly

Calls 7

CreateUniformBufferFunction · 0.85
GetAlignedMethod · 0.80
GetAlignedSizeMethod · 0.80
ApplyParamDescriptorMethod · 0.80
sizeMethod · 0.45
emplace_backMethod · 0.45
GetDeviceMethod · 0.45

Tested by

no test coverage detected