MCPcopy Create free account
hub / github.com/DragonJoker/RenderGraph / createBuffer

Method createBuffer

source/RenderGraph/ResourceHandler.cpp:165–222  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

163 }
164
165 ResourceHandler::CreatedT< VkBuffer > ResourceHandler::createBuffer( GraphContext & context
166 , BufferId bufferId )
167 {
168 ResourceHandler::CreatedT< VkBuffer > result{};
169
170 if ( context.vkCreateBuffer )
171 {
172 lock_type lock( m_buffersMutex );
173 auto [it, ins] = m_buffers.try_emplace( bufferId, std::pair< VkBuffer, VkDeviceMemory >{} );
174
175 if ( ins && context.device )
176 {
177 // Create buffer
178 auto createInfo = reshdl::convert( *bufferId.data );
179 auto res = context.vkCreateBuffer( context.device
180 , &createInfo
181 , context.allocator
182 , &it->second.first );
183 result.resource = it->second.first;
184 checkVkResult( res, "Buffer creation" );
185 crgRegisterObjectName( context, bufferId.data->name, result.resource );
186
187 // Create Buffer memory
188 VkMemoryRequirements requirements{};
189 context.vkGetBufferMemoryRequirements( context.device
190 , result.resource
191 , &requirements );
192 uint32_t deduced = context.deduceMemoryType( requirements.memoryTypeBits
193 , getMemoryPropertyFlags( bufferId.data->info.memory ) );
194 VkMemoryAllocateInfo allocateInfo{ VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO
195 , nullptr
196 , requirements.size
197 , deduced };
198 res = context.vkAllocateMemory( context.device
199 , &allocateInfo
200 , context.allocator
201 , &it->second.second );
202 result.memory = it->second.second;
203 checkVkResult( res, "Buffer memory allocation" );
204 crgRegisterObjectName( context, bufferId.data->name, result.memory );
205
206 // Bind buffer and memory
207 res = context.vkBindBufferMemory( context.device
208 , result.resource
209 , result.memory
210 , 0u );
211 checkVkResult( res, "Buffer memory binding" );
212 result.created = true;
213 }
214 else
215 {
216 result.resource = it->second.first;
217 result.memory = it->second.second;
218 }
219 }
220
221 return result;
222 }

Callers

nothing calls this directly

Calls 5

checkVkResultFunction · 0.85
getMemoryPropertyFlagsFunction · 0.85
createBufferFunction · 0.85
deduceMemoryTypeMethod · 0.80
convertFunction · 0.70

Tested by

no test coverage detected